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
Caputre Opengl Window in X11 with Fast Framerate - Possible
How to Fetch The Logical Name of a Nic Card Given The Ip Address Associated with It
How Does Os Chooses The Next Process to Be Run in Cpu
Building /Lib/Modules/$(Uname -R)/Build While Compiling a Kernel
Linux - Mapping User Space Memory in Kernel Code
How to Rename a Bunch of Files to Eliminate Quote Marks
Pte Structure in The Linux Kernel
Incorrect Rendering in Anaconda + Spyder (Wrong Colours in Text)
Curl Http Post File Upload Using Curl -Data in Linux Command Line
How to Highlight The Differences Between Subsequent Lines in a File
How to Use/Learn Video4Linux2 (On Screen Display) Output APIs
Combine Two Audio Files with a Command Line Tool
Access Podman Rest API from Testcontainer
Profiling Arbitrary Cuda Applications