Answers for "how to share on variable in two processes in fork"

0

how to share on variable in two processes in fork

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

#define   MAX_COUNT  200
#define   BUF_SIZE   100

void  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 = %dn", pid, i);
          write(1, buf, strlen(buf));
     } 
}
Posted by: Guest on January-10-2022

Code answers related to "how to share on variable in two processes in fork"

Browse Popular Code Answers by Language