From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N6O9V-00020z-IM for qemu-devel@nongnu.org; Fri, 06 Nov 2009 07:42:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N6O9Q-0001wC-7v for qemu-devel@nongnu.org; Fri, 06 Nov 2009 07:42:52 -0500 Received: from [199.232.76.173] (port=38429 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N6O9P-0001vw-Tc for qemu-devel@nongnu.org; Fri, 06 Nov 2009 07:42:47 -0500 Received: from mail-qy0-f194.google.com ([209.85.221.194]:44277) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N6O9P-0007IQ-Dh for qemu-devel@nongnu.org; Fri, 06 Nov 2009 07:42:47 -0500 Received: by qyk32 with SMTP id 32so401377qyk.4 for ; Fri, 06 Nov 2009 04:42:47 -0800 (PST) Message-ID: <4AF419C4.6030108@codemonkey.ws> Date: Fri, 06 Nov 2009 06:42:44 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 0/4] net-bridge: rootless bridge support for qemu References: <1257294485-27015-1-git-send-email-aliguori@us.ibm.com> <20091105163702.GC21630@shareable.org> <4AF30129.7080203@us.ibm.com> <200911051820.48878.arnd@arndb.de> <4AF3154F.8090901@redhat.com> <4AF32E78.1040103@us.ibm.com> <4AF3CED1.7080207@redhat.com> <20091106105407.GA17195@shareable.org> In-Reply-To: <20091106105407.GA17195@shareable.org> Content-Type: multipart/mixed; boundary="------------040203050000000004080003" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jamie Lokier Cc: Mark McLoughlin , Anthony Liguori , Arnd Bergmann , Arnd Bergmann , Juan Quintela , Dustin Kirkland , qemu-devel@nongnu.org, Michael Tsirkin , Avi Kivity This is a multi-part message in MIME format. --------------040203050000000004080003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jamie Lokier wrote: > Avi Kivity wrote: > >>> I know this has been discussed before, but isn't this why there are >>> things like vfork()? >>> >> vfork() doesn't work with threads - it requires that the calling process >> be halted until exec() is called. >> > > On Linux (NPTL), vfork() is good for this. It only halts the calling > thread. Other threads continue to run, and when the vfork'd thread > called exec*(), it doesn't affect the other threads. Of course this > behaviour isn't portable, but then again, neither is KVM. > Yup, see attached program. Here's the output which confirms this is the case. tick sleeping tick tick tick tick tick tick tick tick tick done sleeping vfork() returned hello world Regards, Anthony Liguori --------------040203050000000004080003 Content-Type: text/x-csrc; name="vfork.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vfork.c" #include #include #include #include #include #include static void *tick_thread(void *unused) { while (1) { pthread_testcancel(); printf("tick\n"); sleep(1); } return NULL; } int main(int argc, char **argv) { pid_t pid; pthread_t tid; void *ret; if (pthread_create(&tid, NULL, tick_thread, NULL) < 0) { printf("pthread_create failed\n"); return 1; } pid = vfork(); if (pid == 0) { printf("sleeping\n"); sleep(10); printf("done sleeping\n"); execl("/bin/echo", "echo", "hello world", NULL); exit(1); } else if (pid > 0) { printf("vfork() returned\n"); waitpid(pid, NULL, 0); } else { printf("vfork failed\n"); return 1; } pthread_cancel(tid); pthread_join(tid, &ret); return 0; } --------------040203050000000004080003--