Join or create a process group
#include <process.h> int setpgid( pid_t pid, pid_t pgid );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The setpgid() function is used either to join an existing process group or to create a new process group within the session of the calling process. The process group ID of a session leader doesn't change.
The following definitions are worth mentioning:
On successful completion, the process group ID of the process with a process ID matching pid is set to pgid. As a special case, you can specify either pid or pgid as zero, meaning that the process ID of the calling process is to be used.
/* * The process joins process group 0. */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <process.h> int main( void ) { if( setpgid( getpid(), 0 ) == -1 ) { perror( "setpgid" ); } printf( "%d belongs to process group %d\n", getpid(), getpgrp() ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |