|
|
请高手帮忙解释如下程序的输出:
- #include <signal.h>
- #include <unistd.h>
- #include "ourhdr.h"
- int
- main(void)
- {
- pid_t pid;
- printf("%s",getlogin());
- if ( (pid = fork()) < 0)
- err_sys("fork error");
- else if (pid != 0) { /* parent */
- sleep(2);
- exit(2); /* terminate with exit status 2 */
- }
- if ( (pid = fork()) < 0)
- err_sys("fork error");
- else if (pid != 0) {
- sleep(4);
- abort(); /* terminate with core dump */
- }
- /* second child */
- if ( (pid = fork()) < 0)
- err_sys("fork error");
- else if (pid != 0) {
- execl("/usr/bin/dd", "dd", "if=/boot", "of=/dev/null", NULL);
- exit(7); /* shouldn't get here */
- }
- /* third child */
- if ( (pid = fork()) < 0)
- err_sys("fork error");
- else if (pid != 0) {
- sleep(4);
- exit(0); /* normal exit */
- }
- /* fourth child */
- sleep(6);
- kill(getpid(), SIGKILL); /* terminate with signal, no core dump */
- exit(6); /* shouldn't get here */
- }
复制代码
如果login:root, 输出为rootrootrootroot,为什么? |
|