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
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