/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* sample program to show how signal() is used */
#include <stdio.h>
#include <signal.h>
int delay = 1;
void childHandler();

int main()
{
   int pid;
   char *argv[4];
   
   argv[0]=strdup("ls");
   argv[1]=strdup("-s");
   argv[2]=strdup("signal.c");
   argv[3]=NULL;
   signal(SIGCHLD, childHandler);
   pid=fork();
   if(pid==0)
   {
      execvp("ls",argv);
      perror("limit");
   }
   else
   {
      sleep(delay);
      printf("Child %d exceeded limit and is being killed \n",pid);
      kill(pid, SIGINT);
   }
}

void childHandler()
{
   int childPid, childStatus;
   childPid=wait(&childStatus);
   printf("Child %d terminated within %d seconds \n", childPid, delay);
   exit(0);
}
