Advertisement
Guest User

fork test

a guest
Mar 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "unistd.h"
  3.  
  4. int main(void)
  5. {
  6.     int st = 0;
  7.    
  8.     while (1)
  9.     {
  10.         if (fork() == 0)
  11.         {
  12.             usleep(10);
  13.             break;
  14.         }
  15.         else
  16.         {
  17.             ++st;
  18.             usleep(100);
  19.         }
  20.     }
  21.     printf("step=%d, pid=%d\n", st, getpid());
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement