LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 04: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, 05: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, 05: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, 05: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



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 09:11 AM
about wait ringerxyz Programming 1 02-02-2005 12:00 AM
over-fork luzi82 Linux - Newbie 2 01-02-2004 06:55 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM
Fork Ztyx Linux - General 1 08-31-2002 11:25 AM

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

All times are GMT -5. The time now is 06:19 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
Open Source Consulting | Domain Registration