Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
5
Добавлен:
26.05.2014
Размер:
2.14 Кб
Скачать
/***************************************************************************
                          main.c  -  description
                             -------------------
    begin                : уТД нБК  5 03:04:56 MSD 2004
    copyright            : (C) 2004 by бМЕЛУЕК
    email                : achernok@mail.ru
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
static int onsigint(int sig);
static pid_t fd1[2],fd2[2];
static pid_t spid;
static int buff[2];
int main(int argc, char *argv[])
{
  signal(SIGINT,&onsigint);
  pipe(fd1);
  pipe(fd2);
  switch (spid=fork())
  {
    case 0 :while(1)
            {
              sleep(1);
              read(fd1[0],buff,2);
              printf("SECOND process recieved:%s from FIRST process\n",buff);
              buff[0]='2';
              buff[1]='1';
              sleep(1);
              write(fd2[1],buff,2);
            }
    
    default:while(1)
            {
              buff[0]='1';
              buff[1]='2';
              sleep(1);
              write(fd1[1],buff,2);
              sleep(1);
              read(fd2[0],buff,2);
              printf("FIRST process recieved:%s from SECOND process\n",buff);
            }
  }

  return EXIT_SUCCESS;
}

int onsigint(int sig)
{
  signal(SIGINT,&onsigint);
  printf("Recieved signal to abort process %d\n",getpid());
  exit(0);
}
Соседние файлы в папке lab3
  • #
    26.05.20142.14 Кб531.c
  • #
    26.05.201411.99 Кб4a.out