1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
/* mise en arriere plan */
if (do_debug || do_nofork)
{
/* fermeture entrée/sorties standard */
close(0);
/*if (open("/dev/tty", O_RDWR) == -1)
{
fprintf(stderr, "ERREUR: impossible d'ouvrir /dev/tty [%s]\n", strerror(errno));
exit(EXIT_FAILURE);
}*/
mypid = fork();
if (mypid < 0)
{
fprintf(stderr, "ERREUR: la tentative de mise en arrière plan a échouée [%s]\n", strerror(errno));
exit(EXIT_FAILURE);
}
else if (mypid != 0)
{
printf("Identifiant du processus: %d\n", (int) mypid);
exit(EXIT_SUCCESS);
}
/* demarre une nouvelle session */
if (setsid() < 0)
{
fprintf(stderr, "ERREUR: impossible de démarrer une nouvelle session\n");
exit(EXIT_FAILURE);
}
} |
Partager