Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing the parent process to run first

On my system(Opensuse) by default the child process always executes first, after fork. There are also ways to force the child process to run first. I would like to know if there is any way to force the parent process to run first?

like image 935
ram619 Avatar asked Nov 20 '25 08:11

ram619


1 Answers

You can use this method

pid_t pid = fork();
if (pid == -1)
    abort();
else if (pid == 0) 
{
    raise(SIGSTOP); // stop the child
} 
else 
{
    waitpid(pid, NULL, WUNTRACED); // wait until the child is stopped
    kill(pid, SIGCONT); // resume the child
}
like image 92
Anjaneyulu Avatar answered Nov 21 '25 21:11

Anjaneyulu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!