- 论坛徽章:
- 1
|
系统:- $ uname -a
- Linux yuhuashi-Linux 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
复制代码 测试代码:- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #include <stdlib.h>
- int main (void)
- {
- pid_t pid;
- fflush(NULL);
- pid = fork();
- if (pid < 0)
- {
- perror("fork()");
- exit(errno);
- }
- if (0 == pid)
- {
- printf("chlidren run\n");
- int i = 0;
- for (i = 0; i < 30; i++)
- {
- printf("%d\n", i);
- sleep(1);
- }
- exit(0);
- }
- sleep(5);
- printf("parend exit\n");
- exit(0);
- return 0;
- }
复制代码 父进程未退出时:- $ ps -axj
- PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
- 8474 8505 8505 8505 pts/6 8692 Ss 1000 0:00 bash
- 8505 8692 8692 8505 pts/6 8692 S+ 1000 0:00 ./a.out --父进程
- 8692 8693 8692 8505 pts/6 8692 S+ 1000 0:00 ./a.out --子进程
复制代码 父进程退出后:- $ ps -axj
- PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
- 2153 2166 2166 2166 ? -1 Ss 1000 0:00 init --user
- 2166 8693 8692 8505 pts/6 8505 S 1000 0:00 ./a.out
复制代码 子进程没有被1号init收养,被2153 init --user 收养了,这个init --user 是个神马东西? |
|