Fork question.

G

Gvs

Hi,

I'm just playing around with forking processes and was wondering how can you
keep a child alive as long as the parent is alive. To give an example here
is my code.

-----------------------------------------------------------------------
for(i=0; i<2; i++) {

if((pid = fork()) == -1) //run the fork command
{
perror("fork");
}

else if (pid == 0)
{
if (i ==0) //using parent process
{
//start the timer function
time = 20;
timer(time);
}
else if () //using children processes
{
//start the timer function
timer = 10;
timer(time);
exit(1);
}

void timer(int time)
{
sleep(time);
}

-------------------------------------------------------

I want to keep the child alive even though his timer is smaller than the
parents. I need to check if the parent is still alive before killing the
child, if the parent is then allow the child to remain alive.

Regards,

Matt
 
A

Artie Gold

Gvs said:
Hi,

I'm just playing around with forking processes and was wondering how can you
keep a child alive as long as the parent is alive. To give an example here
is my code.
Sorry, but fork() is not part of standard C.

Try
HTH,
--ag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linux: using "clone3" and "waitid" 0
fork() 5
fork() 27
C pipe 1
Communicating between processes 0
fork/exec question 6
'fork' query 3
How to use shared memory with fork() ? 5

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top