#include <stdio.h>
#include <unistd.h>
int main()
{
int id;
printf("here comes the date.\n");
if (id = fork() == 0) {
printf(“%d”, id);
printf ("PID is %d and ID is %d\n", getpid (),id);
execl ("/bin/date", "date", 0);
}
printf ("that was the date.\n");
}
输出:
here comes the date.
that was the date.
PID is 1414 and ID is 1
Tue Feb 10 14:03:02 PST 2015
答案 0 :(得分:0)
因为您将其设置为fork() == 0
的结果,这是一个逻辑测试。
Fork将在分叉线程内成功(返回零)。外部线程将具有PID。