Universidad de Costa Rica

Escuela de Ciencias de la Computación e Informática

CI-0122 Sistemas operativos

Ejemplos

CI0122 / Ejemplos / fork


#include  <stdio.h>
     #include  <string.h>
     #include  <sys/types.h>

     #define   MAX_COUNT  50
     #define   BUF_SIZE   100

     int  main(void)
     {
          pid_t  pid;
          int    i;
          char   buf[BUF_SIZE];

          fork();
          pid = getpid();
          for (i = 1; i <= MAX_COUNT; i++) {
               sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
               write(1, buf, strlen(buf));
          } 
     }