Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
4
Добавлен:
26.05.2014
Размер:
785 б
Скачать
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <unistd.h>

int main()
{
char ch;
int pid1,pid2,dead1,dead2,status1,status2;
system("clear");
printf("Grand: PID: %d\n",getpid());
switch(pid1=fork())
{
case -1: printf("Error with fork Grand->Dad\n");exit(-1);
case  0: printf("Dad: PID: %d\n",getpid());
	switch(pid2=fork())
	{
	case -1: printf("Error with fork dad=>child\n");exit(-1);
	case  0: printf("Child: PID: %d\n",getpid());
        while 1 { 
		sleep(100) 
		}
	default: dead2=wait(&status2);
	}
while 1 {
	sleep(100)
	}
printf("Child KILLED: PID was: %d; STATUS: %d\n",dead2,status2>>8);
exit(1);
default: dead1=wait(&status1);
}
printf("Dad KILLED: PID was: %d; STATUS: %d\n",dead1,status1>>8);
return 0;
}
Соседние файлы в папке 1
  • #
    26.05.2014818 б41st.c
  • #
    26.05.2014785 б41st1.c
  • #
    26.05.201411.82 Кб4a.out
  • #
    26.05.201420 б4go.sh
  • #
    26.05.201411.94 Кб5lab1
  • #
    26.05.2014803 б5main.c
  • #
    26.05.2014827 б4main.c.save