Esempio n. 1
0
int main(int argc, char **argv) {
  int pid, x;

  if (argc == 2) 
    x = atoi(argv[1]);
      
  else {
    printf("Usage:  %s nombre\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  
  if ( x < 0 ) {
	  printf("Error: number '%d' need to be positive or null\n", x);
	  exit(EXIT_FAILURE);
  }
  else if ( x > 255) {
	  printf("Error: number '%d' need to be under 255\n", x);
	  exit(EXIT_FAILURE);
  }

  pid = fork();

  if (pid != 0) {	/* Processus Pere */
    signal(SIGCLD, fin_fils);
    travail();
  } else {		/* Processus Fils */
    sleep(10);
    exit(x);
  }
}
Esempio n. 2
0
int main() {
  printf("PID: %d\n", getpid());
  signal(SIGINT,hdl_sys1);
  signal(SIGQUIT,hdl_sys2);
  /* ? ? ? ? ? ? */
  
  travail();
}
Esempio n. 3
0
int main() {
  // Register a handler for SIGILL.
  if (signal(SIGILL, hdl_sys1) == SIG_ERR) {
    fprintf(stderr, "Cannot register handler for SIGILL");
  }
  // Register a handler for SIGINT and SIGQUIT.
  if (sigaction(SIGINT, &action_1, (void *) NULL) != 0) {
    fprintf(stderr, "Cannot register handler for SIGINT");
  }
  if (signal(SIGQUIT, toggle_message) == SIG_ERR) {
    fprintf(stderr, "Cannot register handler for SIGQUIT");
  }
  
  printf("PID: %d\n", getpid());
  
  travail();
}
Esempio n. 4
0
int main(int argc, char **argv) {
  int pid, x;

  if (argc == 2)
    x = atoi(argv[1]);
  else {
    printf("Usage:  %s nombre\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  pid = fork();

  if (pid != 0) {	/* Processus Pere */
    signal(SIGCHLD, fin_fils);
    travail();
  } else {		/* Processus Fils */
    sleep(30);
    exit(x);
  }
}
Esempio n. 5
0
/* --------------------------------------------------------- */
int main(int argc, char * argv[]) 
{
  int fd, c;
  FILE *in, *out;
  
  /* gestion des options : -v ou -h */
  while ((c=getopt(argc, argv, "vh")) != -1)
    switch (c) {
    case 'v':
      VERBOSE = 1;
      break;
    case 'h':
      printf("usage: export POPHOST=boite ou pop\n"
             "       export POPUSER=login\n"
             "       export POPPWD=.....\n"
             "puis\n"
             "       pop [-vh]\n");
      exit(0);
      break;
    default:
      printf("option inconnue\n");
      exit(0);
      break;
    };

  /* nom de la machine interrogee, nom de l'utilisateur et son mot de passe */
  /* recuperes dans l'environnement */
  hostname = getenv("POPHOST");
  if (hostname==NULL) hostname = getenv("HOSTNAME");
  if (hostname==NULL) {
    fprintf(stderr,"* Définir le nom de machine dans la variable POPHOST\n");
    exit(1);
  }
  if (VERBOSE)
    printf("     POPHOST = %s\n",hostname);

  username = getenv("POPUSER");
  if (username==NULL) username = getenv("LOGNAME");
  if (username==NULL) {
    fprintf(stderr,"* Définir le nom de l'utilisateur dans la variable POPUSER\n");
    exit(1);
  }
  if (VERBOSE)
    printf("     POPUSER = %s\n",username);

  password = getenv("POPPWD");
  if(password == NULL) {
    fprintf(stderr,"* Définir le mot de passe dans la variable POPPWD\n");
    exit(1);
  }
  
  /* ouverture de la connexion */
  fd=connexion(hostname,PORT);
  
  /* Ouverture de fichiers de haut niveau (cf. polycop systeme) */
  in  = fdopen(fd,"r");
  out = fdopen(fd,"w");

  /* travail */
  travail(in,out);

  close(fd);
  exit(0);
}