#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h> // здесь содержаться fork();,wait();,getpid();
#include <stdlib.h> //из-за нехватки этой библиотеки не работал exit();
void main(void)
{
int pid2, pid3, st; /* process 1 */
printf("Process 1, pid = %d:n", getpid());
pid2 = fork();
if (pid2 < 0)
printf("Cann't create process 2: error %dn", pid2);
if (pid2 == 0)
{ /* process 2 */
printf("Process 2, pid = %d:n", getpid());
pid3 = fork();
if (pid3 < 0)
printf("Cann't create process 3: error %dn", pid3);
if (pid3 == 0)
{ /* process 3 */
printf("Process 3, pid = %d:n", getpid());
sleep(2);
printf("Process 3: endn");
/* process 2 */
wait(&st);
printf("Process 2: endn");
/* process 1 */
wait(&st);
printf("Process 1: endn");
}
}
exit(0);
}