/* Demonio tipo UNIX, codigo de ejemplo. UNIX Daemon, example code rules. By: Por: Oscar Medina Duarte is111936@mail.udlap.mx */ #include #include #include #include #include #include void damncode(); void teschingando(int); void setduplicate(int); main(){ pid_t pid; signal(SIGINT,teschingando); signal(SIGUSR1, setduplicate); pid = fork(); if (pid <0){ printf("Forking Error : )\n"); exit(-1); }else if (pid !=0 ){ printf("\nThis is a Father 1\n"); }else{ pid = fork(); if (pid <0){ printf("Forking error : )\n"); exit(-1); }else if (pid !=0 ){ printf("\nThis is a father 2\n"); }else{ /* Poner en modo daemon */ /* Set Daemon mode */ setsid(); umask(0); chdir("/"); damncode(); /* Y ejecutar el daemon, run the daemon */ } } } void damncode(){ printf("Daemon :\n PID %d\tPPID %d\n",getpid(),getppid()); for(;;); } void teschingando(int signo){ printf("Signal : %d",signo); exit(1); } void setduplicate(int signo){ main(); }