#include <sys/types.h> #include <unistd.h> pid_t fork()
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid; // プロセスID
// 子プロセス
if ((pid = fork()) == 0) {
printf("子プロセス\n");
printf(" 子プロセスの処理\n");
exit(0);
}
// 親プロセス
printf("親プロセス(PID = %d)\n", pid);
printf(" 親プロセスの処理\n");
return 0;
}
(出力)
子プロセス
子プロセスの処理
親プロセス(PID = 1001)
親プロセスの処理
| ホームページ | 目次 | 演習解答例目次 | 付録目次 | 索引 |