Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
4
Добавлен:
26.05.2014
Размер:
2.07 Кб
Скачать
/***************************************************************************
                          main.c  -  description
                             -------------------
    begin                : юФЧ нБК  6 01:12:01 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 <signal.h>
#include <wait.h>
#include <string.h>
static int onsigint(int sig);
int i=1,status;
static pid_t cpid,npid,fd[2];
char path[50]="/bin/";
int status;
int main(int argc, char *argv[])
{
  signal(SIGINT,&onsigint);
  pipe(fd);
  printf("Argc=%d\n",argc);
  for(i>0;i<argc;i++)
  {
  switch(cpid=fork())
     {
       case -1:;
       case  0:path[50]=strcat(&path,argv[i]);
               printf("PATH=%s\n",path);
               printf("COMMAND=%s\n",argv[i]);
               dup2(fd[0],stdin);
               close(fd[0]);
               if (i!=argc)
               {
                 dup2(fd[1],stdout);
                 close(fd[1]);
               }
               execl(path,argv[i],NULL);
               printf("EXECL ERROR !!!!!!!!\n");
       default:wait(&status);
		 	
     }
  }

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