From owner-freebsd-hackers Thu Aug 26 7:41:10 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from duke.cs.duke.edu (duke.cs.duke.edu [152.3.140.1]) by hub.freebsd.org (Postfix) with ESMTP id AE46515C98 for ; Thu, 26 Aug 1999 07:40:53 -0700 (PDT) (envelope-from gallatin@cs.duke.edu) Received: from grasshopper.cs.duke.edu (grasshopper.cs.duke.edu [152.3.145.30]) by duke.cs.duke.edu (8.9.1/8.9.1) with ESMTP id KAA07648 for ; Thu, 26 Aug 1999 10:40:29 -0400 (EDT) Received: (from gallatin@localhost) by grasshopper.cs.duke.edu (8.9.3/8.9.1) id KAA06735; Thu, 26 Aug 1999 10:40:29 -0400 (EDT) (envelope-from gallatin@cs.duke.edu) From: Andrew Gallatin MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 26 Aug 1999 10:40:29 -0400 (EDT) To: freebsd-hackers@freebsd.org Subject: undocumented vfork behaviour? X-Mailer: VM 6.43 under 20.4 "Emerald" XEmacs Lucid Message-ID: <14277.18939.326895.354112@grasshopper.cs.duke.edu> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'm working on getting linux/alpha compatability going in FreeBSD/alpha & I stumbled over some odd fork behaviour that I was hoping somebody could shed some light on. Specifically, when a linux/alpha process forks, the child's return value is the parent's pid rather than zero. I tracked this behaviour down to the child's code path in the alpha's cpu_fork(): /* * Set up return-value registers as fork() libc stub expects. */ p2tf->tf_regs[FRAME_V0] = p1->p_pid; /* parent's pid */ p2tf->tf_regs[FRAME_A3] = 0; /* no error */ p2tf->tf_regs[FRAME_A4] = 1; /* is child */ In the i386 & mips libc Ovfork stubs, I see comments which describe this behaviour: /* * pid = vfork(); * * %edx == 0 in parent process, %edx == 1 in child process. * %eax == pid of child in parent, %eax == pid of parent in child. * */ Is this comment purely historical? At least the i386 platform no longer seems to do this: If I run the following code on FreeBSD/i386, I see: parent's pid = 6730 I am the child, result = 0 I must be the parent, result = 6731 Whereas FreeBSD/alpha does this: parent's pid = 17721 I must be the parent, result = 17721 I must be the parent, result = 17722 Code: #include #include main() { int result; printf("parent's pid = %d\n", getpid()); result = syscall(SYS_vfork); if(result == 0) printf("I am the child, result = %d\n", result); else printf("I must be the parent, result = %d\n", result); exit(); } Before I "fix it" to act like FreeBSD/i386 (I've already tried & it seems to work OK for FreeBSD & OSF1 binaries, and fixes my linux/alpha binary's problems), I'd like to make sure there aren't any hidden ramifications. Thanks, Drew ------------------------------------------------------------------------------ Andrew Gallatin, Sr Systems Programmer http://www.cs.duke.edu/~gallatin Duke University Email: gallatin@cs.duke.edu Department of Computer Science Phone: (919) 660-6590 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message