1.终端登录
2.网络登录
3.进程组
#include <unistd.h> pid_t getpgrp(void);
|
Returns: process group ID of calling process |
#include <unistd.h>
pid_t getpgid(pid_t pid);
|
Returns: process group ID if OK, 1 on error |
#include <unistd.h> int setpgid(pid_t pid, pid_t pgid);
|
Returns: 0 if OK, 1 on error |
4.会话
建立会话
#include <unistd.h> pid_t setsid(void);
|
Returns: process group ID if OK, 1 on error |
返回会话的首进程的进程组ID
#include <unistd.h>
pid_t getsid(pid_t pid);
|
Returns: session leader's process group ID if OK, 1 on error |
5.控制终端
6.tcgetpgrp,tcsetpgrp 和tcgetsid函数
#include <unistd.h>
pid_t tcgetpgrp(int filedes);
|
Returns: process group ID of foreground process group if OK, 1 on error |
int tcsetpgrp(int filedes, pid_t pgrpid);
|
Returns: 0 if OK, 1 on error |
#include <termios.h>
pid_t tcgetsid(int filedes);
|
Returns: session leader's process group ID if OK, 1 on error |
7.作业控制
8.shell执行程序
9.孤儿进程组
例:
创建一个孤儿进程组
#include "apue.h" #include <errno.h> static void sig_hup(int signo) { printf("SIGHUP received, pid = %d\n", getpid()); } static void pr_ids(char *name) { printf("%s: pid = %d, ppid = %d, pgrp = %d, tpgrp = %d\n", name, getpid(), getppid(), getpgrp(), tcgetpgrp(STDIN_FILENO)); fflush(stdout); } int main(void) { char c; pid_t pid; pr_ids("parent"); if ((pid = fork()) < 0) { err_sys("fork error"); } else if (pid > 0) { /* parent */ sleep(5); /*sleep to let child stop itself */ exit(0); /* then parent exits */ } else { /* child */ pr_ids("child"); signal(SIGHUP, sig_hup); /* establish signal handler */ kill(getpid(), SIGTSTP); /* stop ourself */ pr_ids("child"); /* prints only if we're continued */ if (read(STDIN_FILENO, &c, 1) != 1) printf("read error from controlling TTY, errno = %d\n", errno); exit(0); } }