Hi Ketan, Its clear now. But suppose the child doesn't terminate for a long time, say its going through an infinite loop, the we have to kill the child right? Or better not write such code. Thanks. Gowri. -----Original Message----- From: Ketan Mukadam [mailto:kmukadam@neomagic.com] Sent: Thursday, March 04, 2004 11:46 AM To: Gowri Ramasubramanian Cc: Florin Malita; kernelnewbies@nl.linux.org Subject: Re: some trivial problem with fork Hi Gowri, No You do not "get back" the prompt after the child exits, but when you run your application at the prompt, and as soon as your parent thread dies, the shell is free and it returns the prompt[even though the child is still alive]. After that the child thread writes the "hello" string on the terminal and it exits. Since the prompt is already there you do not get any extra prompt.... Hope its clear.... Ketan Gowri Ramasubramanian wrote: >Thanks Florin. > >But my doubt still remains. > >The child exits after the parent exits. So in this case the child is >inherited by init process. > >I get it till here. But after the child terminates, I get the prompt back >and am not able to see it. Am able to do everything as I can do at a prompt >because it is the prompt the parent returned? > >Now when the child exits, will it give the prompt back to me(along with the >stack, heap etc copies does the child get the shell too?). If it does I >don't see it. > >Finally, as the child has been inherited by init, what happens after the >child exits? > >Am confused. > >Thanks. >Gowri. >-----Original Message----- >From: Florin Malita [mailto:mali@go.ro] >Sent: Wednesday, March 03, 2004 6:39 PM >To: kernelnewbies@nl.linux.org >Cc: Gowri Ramasubramanian >Subject: RE: some trivial problem with fork > > >Your parent process exits before the child, so you get the prompt back. Then >the child prints the message/flushes buffers/exits so you get the message >showing up after the prompt. > >Add a wait/waitpid call before the parent exits to make it wait for the >child result. > >Florin > >-----Original Message----- >From: kernelnewbies-bounce@nl.linux.org >[mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of Gowri >Ramasubramanian >Sent: Wednesday, March 03, 2004 6:40 AM >To: kernelnewbies@nl.linux.org >Subject: some trivial problem with fork > >Hi All, > >I know this is very trivial. Might be am missing something out. >Have attached the code > >When I run the code I get to see "hello" on stdout and then get the prompt >but am not able to see it. > >What i mean is say the prompt is prompt> > >prompt>./a.out >prompt>hello > >I get a prompt and then see hello >and I don't see the prompt after hello. > >Actually what I expect is > >prompt>./a.out >helloprompt> > >But if I type "ls" or anything after hello it shows the output. So it means >that the prompt is there. > >What I mean is >prompt>./a.out >prompt>helloecho hi >hi >prompt> > >Hope I have been clear. Thanks. >Gowri. > > > >-- >Kernelnewbies: Help each other learn about the Linux kernel. >Archive: http://mail.nl.linux.org/kernelnewbies/ >FAQ: http://kernelnewbies.org/faq/ > >. > > > -- "If you view your problem closely enough you will recognize yourself as part of the problem." - Ducharm's Axiom -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/