Posted By

whitetiger on 11/09/06


Tagged

http math python c dynamic perl binary char world lines hello memory manager block allocator reallocator interseccion palindrome daemon fork


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

yuconner
ahy1
copyleft


C - create Process Daemon


 / Published in: C++
 

  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. /*
  10. * Funzione che mi crea un demone
  11. */
  12.  
  13. int pid;
  14.  
  15. // create - fork 1
  16. if(fork()) return 0;
  17.  
  18. // it separates the son from the father
  19. chdir("/");
  20. setsid();
  21. umask(0);
  22.  
  23. // create - fork 2
  24. pid = fork();
  25.  
  26. if(pid)
  27. {
  28. printf("Daemon: %d\n", pid);
  29. return 0;
  30. }
  31.  
  32. /****** Codice da eseguire ********/
  33. FILE *f;
  34.  
  35. f=fopen("/tmp/coa.log", "w");
  36.  
  37. while(1)
  38. {
  39. fprintf(f, "ciao\n");
  40. fflush(f);
  41. sleep(2);
  42. }
  43. /**********************************/
  44. }

Report this snippet  

You need to login to post a comment.