155

Créer un processus zombie

  1. /*
  2.  * Creates a zombie process.
  3.  *
  4.  *   fork
  5.  *   getpid
  6.  *   getppid
  7.  *   sleep
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <errno.h>
  16. #if defined( LINUX )
  17. #include <string.h>
  18. #endif
  19.  
  20. #define SLEEPTIME               2               /* in secs */
  21.  
  22. int main( int argc, char **argv ) {
  23.     int pid;
  24.  
  25.     fprintf( stdout, "%i running...\n", getpid() );
  26.  
  27.     pid = fork();
  28.  
  29.     if ( pid == -1 ) { /* error */
  30.         fprintf( stderr, "%s\n", strerror( errno ) );
  31.         exit( 1 );
  32.     }
  33.  
  34.     if ( pid == 0 ) { /* child */
  35.         fprintf( stdout, "%i with parent %i...\n", getpid(), getppid() );
  36.         fprintf( stdout, "%i sleeping for %i secs...\n", getpid(), SLEEPTIME );
  37.         sleep( SLEEPTIME );
  38.         fprintf( stdout, "%i with parent %i...\n", getpid(), getppid() );
  39.         exit( 0 );
  40.     }
  41.  
  42.     /* don't wait for child (zombie) */
  43.     fprintf( stdout, "%i bye\n", getpid() );
  44.  
  45.     exit( 0 );
  46. }

Commentaires

Votre commentaire :
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip aide 2000

Entrez un maximum de 2000 caractères.
Améliorez la présentation de votre texte avec les balises de formatage suivantes :
[p]paragraphe[/p], [b]gras[/b], [i]italique[/i], [u]souligné[/u], [s]barré[/s], [quote]citation[/quote], [pre]tel quel[/pre], [br]à la ligne,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]commande[/code], [code=langage]code source en c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].