LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2006, 05:29 AM   #1
asdandekar
LQ Newbie
 
Registered: Sep 2006
Distribution: Xubuntu
Posts: 6

Rep: Reputation: 0
Question An example of fork() and wait() functions


Please tell me how to use fork() and wait() functions to create a child process and transform that process into a zombie state.
 
Old 09-28-2006, 06:39 AM   #2
scoban
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: Slackware
Posts: 145

Rep: Reputation: 16
Take a look at here:

http://www.cs.cf.ac.uk/Dave/C/node22...00000000000000
 
Old 09-28-2006, 06:55 AM   #3
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
The link above tells you how to fork() a process.
To create 'zombies' I believe you have to use
signal handlers.
When a child process terminates it send SIGCHLD signal
to its parent process .
If the parent process *ignores* the SIGCHLD signal
the child becomes a zombie.
 
Old 09-29-2006, 06:33 PM   #4
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
To transform the child process into a zombie you just have it call exit(), and have the parent not pay attention to the SIGCHLD signal as pankaj99 said.

I use waitpid(-1, NULL, WNOHANG); in the parent process to clean up any zombie children, since in the program that uses it I don't care when or why the child exited.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 10:11 AM
about wait ringerxyz Programming 1 02-02-2005 01:00 AM
over-fork luzi82 Linux - Newbie 2 01-02-2004 07:55 AM
pointers to functions/member functions champ Programming 2 03-28-2003 07:22 PM
Fork Ztyx Linux - General 1 08-31-2002 12:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration