/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int main(int argc, char *argv[]) { /* * Funzione che mi crea un demone */ int pid; // create - fork 1 if(fork()) return 0; // it separates the son from the father chdir("/"); setsid(); umask(0); // create - fork 2 pid = fork(); if(pid) { printf("Daemon: %d\n", pid); return 0; } /****** Codice da eseguire ********/ FILE *f; f=fopen("/tmp/coa.log", "w"); while(1) { fprintf(f, "ciao\n"); fflush(f); sleep(2); } /**********************************/ }