0

B线是什么意思?我将进程分叉 10 次,显示进程 ID,然后调用wait()10 次。

#include <stdio.h>
#include <unistd.h>

// Fork the process 10 times
for(i = 0; i < 10; i++) {

  // Catch the PID
  if (pid = fork() < 0)
    // error
  else if (pid == 0) {

  function_A();

  return 0;
}

  printf(“process ID: %d \n”, pid); // Line A

}

for(i = 0; i < 10; i++) //Line B

wait();
4

1 回答 1

0

fork()异步启动子进程。意思是,他们开始了,然后被抛到了后台。

wait()告诉计算机“等待”它们结束。

因此,它告诉父进程在继续执行之前等待子进程结束。

https://www.geeksforgeeks.org/wait-system-call-c/

于 2018-05-03T07:24:39.547 回答