Advertisement
999ms

Untitled

Dec 17th, 2020
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6. #include <errno.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. #include <time.h>
  10. #include <signal.h>
  11. #include <sys/signal.h>
  12.  
  13.  
  14. void ProcessWork(pid_t PID, int time) {
  15.     printf("%d\n", time);
  16. }
  17.  
  18. int main(int argc, char* argv[]){
  19.     pid_t pid = 0;
  20.    
  21.     int PID = getpid();
  22.     int n = 10;
  23.     int times[n];
  24.     pid_t all_pid[n];
  25.  
  26.     for (int i = 0; i < n; i++) {
  27.         times[i] = i + 1;
  28.     }
  29.  
  30.     for (int i = 0; i < n; i++) {
  31.         pid = fork();
  32.         if (pid == 0) {
  33.             break;
  34.         } else {
  35.             ProcessWork(pid, times[i]);
  36.         }
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement