From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CbxFI-0005qy-6t for qemu-devel@nongnu.org; Wed, 08 Dec 2004 03:32:24 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CbxFH-0005qm-Ok for qemu-devel@nongnu.org; Wed, 08 Dec 2004 03:32:23 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CbxFH-0005qj-IB for qemu-devel@nongnu.org; Wed, 08 Dec 2004 03:32:23 -0500 Received: from [64.142.19.5] (helo=b.mail.sonic.net) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1Cbx5A-0007X6-0y for qemu-devel@nongnu.org; Wed, 08 Dec 2004 03:21:56 -0500 Received: from 192.168.0.102 (adsl-68-121-165-86.dsl.pltn13.pacbell.net [68.121.165.86]) (authenticated bits=0) by b.mail.sonic.net (8.12.11/8.12.11) with ESMTP id iB88LqsF003362 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 8 Dec 2004 00:21:53 -0800 From: Nile Geisinger Date: Wed, 8 Dec 2004 00:07:27 +0000 References: <200411180138.46857.james@alentdesignsolutions.com> <200411181303.47086.paul@codesourcery.com> <200412031605.10444.james@alentdesignsolutions.com> In-Reply-To: <200412031605.10444.james@alentdesignsolutions.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200412080007.27542.nile@dloo.com> Subject: [Qemu-devel] Trivial (but useful) patch to save qemu pid to file Reply-To: nile@dloo.com, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi everyone, Here's a very trivial patch that allows qemu's pid to be saved to a file. This is useful if you're using qemu as a service, instrumenting it with other code, or doing other unixy things, cheers, Nile --------------------------------------------------------------------------------------------------- diff -bur qemu-copy/vl.c qemu/vl.c --- qemu-copy/vl.c 2004-12-07 22:11:54.898668344 -0500 +++ qemu/vl.c 2004-12-08 00:11:34.232243744 -0500 @@ -2549,6 +2549,7 @@ " (default is CL-GD5446 PCI VGA)\n" #endif "-loadvm file start right away with a saved state (loadvm in monitor)\n" + "-pid file save the qemu process id to a file\n" "\n" "During emulation, the following keys are useful:\n" "ctrl-alt-f toggle full screen\n" @@ -2619,6 +2620,7 @@ QEMU_OPTION_prep, QEMU_OPTION_localtime, QEMU_OPTION_cirrusvga, + QEMU_OPTION_pid, QEMU_OPTION_g, QEMU_OPTION_std_vga, QEMU_OPTION_monitor, @@ -2689,6 +2691,7 @@ /* temporary options */ { "pci", 0, QEMU_OPTION_pci }, { "cirrusvga", 0, QEMU_OPTION_cirrusvga }, + { "pid", HAS_ARG, QEMU_OPTION_pid }, { NULL }, }; @@ -2765,6 +2768,8 @@ char serial_devices[MAX_SERIAL_PORTS][128]; int serial_device_index; const char *loadvm = NULL; + int pid; + FILE * pid_file; #if !defined(CONFIG_SOFTMMU) /* we never want that malloc() uses mmap() */ @@ -3110,6 +3115,11 @@ case QEMU_OPTION_full_screen: full_screen = 1; break; + case QEMU_OPTION_pid: + pid = getpid(); + pid_file = fopen(optarg, "w"); + fprintf(pid_file, "%d", pid); + fclose(pid_file); } } }