进程调用s e t p g i d可以参加一个现存的组或者创建一个新进程组。 int setpgid(pid_t p i d, pid_t p g i d); 将pid 进程的进程组I D设置为p g i d。 如果这两个参数相等,则由pid 指定的进程变成进程组组长。 如果p i d是0,则使用调用者的进程I D。 如果p g i d是0,则由p i d指定的进程I D被用作为进程组I D。 -------------
int setpgid(pid_t pid, pid_t pgid); setpgid() sets the PGID of the process specified by pid to pgid. If pid is zero, then the process ID of the calling process is used. If pgid is zero, then the PGID of the process specified by pid is made the same as its process ID. If setpgid() is used to move a process from one process group to another (as is done by some shells when creating pipe lines), both process groups must be part of the same session (see setsid(2) and creden tials(7)). In this case, the pgid specifies an existing process group to be joined and the session ID of that group must match the session ID of the joining process. 按照man setpgid的解释,以及APUE的解释,如果设置参数pid为0,则会将当前进程的pid设置为参数pid值, 如果参数pgid为0,则会将pid对应的进程组设置为进程的id(也就是创建新的进程组的意思)。 后面还说到如果要改变pid的进程组,则这两个两个进程组必须在同一个会话中。