#include<sys/types.h> #include<unistd.h> // get process group identifier // pid: // process identifier, or 0 standing for calling process // return value: // process group identifier, or -1 for error pid_tgetpgid(pid_t pid);
// set process group identifier // pid: // process identifier, or 0 standing for calling process // pgid: // process group identifier set to, // or 0 standing for creating a group which ID is equal to the calling process ID // return value: // return 0 for success, -1 for error intsetpgid(pid_t pid, pid_t pgid);
// About more // $ man 2 getpgid
getsid、setsid
setsid时,当前进程不能是进程组组长。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// get session identifier // pid: // process identifier, or 0 standing for calling process // return value: // session identifier, or -1 for error pid_tgetsid(pid_t pid); // $ man 2 getsid
// set session identifier // return value: // new session identifier, or -1 for error // NOTE: // If the calling process isn't the group leader, a new session and group which ID is equal to pid will be created. That means the new session will contain the only process, and it is both the leader of session and group. Otherwise, an error will be raised. pid_tsetsid(void); // $ man 2 setsid