How to Start a Process in Its Own Process Group

How to start a process in its own process group?

What do you mean "start a process in its own process group"? The shell launches processes in their own process groups, that's how it does job control (by having a process group for processes in the foreground, and several process groups for every pipeline launched on the background).

To see that the shell launches a new process group for every pipeline, you can do this:

ps fax -o pid,pgid,cmd | less

which will show something like:

11816 11816  |   \_ /bin/bash
4759 4759 | \_ ps fax -o pid,pgid,cmd
4760 4759 | \_ less

Note that the shell has created a new process group for the pipeline, and every process in the pipeline shares the process group.

Edit:

I think I know what you are getting at. You are calling system from Perl. Apparently, sh -c doesn't create new process groups, since it's a shell without job control.

What I would do would be to fork, then on the child:

setpgrp;
system("ps fax -o pid,pgid,cmd");

and wait on the parent.

How to restart a group of processes when it is triggered from one of them in C code

I'have solved problem with "at" daemon in Linux

I invoke 2 system() calls stop & start.

My first attempt was faulty as explained above. execl make a new image and never returns to later execl unless it is succeed

Here is my solution

case 708: /*There is a trigger signal here*/
{
system("echo '/sbin/start.sh' | at now + 2 min");
system("echo '/sbin/stop.sh | at now + 1 min");
}

Signal all processes in process group except self

You cannot send a signal to all members of the group except the sender, but there is a reasonable workaround. Rather than using SIGSTOP (which cannot be handled or ignored), you can use SIGTSTP which by default will have the same effect as SIGSTOP, stopping the process which receives it. To avoid stopping the sender, simply have the sender ignore the signal before it is sent, and then reset the signal disposition to the default after sending signal to the process group.



Related Topics



Leave a reply



Submit