View of xos/tests/orphaned_process_group.c


XOS | Parent Directory | View | Download

/* Copyright (C) 2008  Emmanuel Varoquaux
 
   This file is part of XOS.
 
   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 3 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char **argv)
{
  int pid;
 
  /* le groupe de processus du fils devient orphelin par la mort du pere et recoit SIGHUP */
  printf("Test 1\n");
  if (!(pid = fork())) {
    setpgid(0, 0);
    if (!(pid = fork())) {
      sleep(2);
      printf("child exiting...\n");
      exit(0);
    }
    kill(pid, SIGSTOP);
    sleep(1);
    printf("parent exiting...\n");
    exit(0);
  }
 
  sleep(4);
 
  /* le groupe de processus du fils ne devient pas orphelin par la mort du pere */
  printf("Test 2\n");
  if (!(pid = fork())) {
    if (!(pid = fork())) {
      sleep(2);
      printf("child exiting...\n");
      exit(0);
    }
    kill(pid, SIGSTOP);
    sleep(1);
    printf("parent exiting...\n");
    exit(0);
  }
 
  sleep(4);
 
  /* le groupe de processus du fils devient orphelin par la mort du pere mais ne recoit pas SIGHUP */
  printf("Test 3\n");
  if (!(pid = fork())) {
    setpgid(0, 0);
    if (!(pid = fork())) {
      sleep(2);
      printf("child exiting...\n");
      exit(0);
    }
    sleep(1);
    printf("parent exiting...\n");
    exit(0);
  }
 
  sleep(4);
 
  return 0;
}