waitpid() を使用するためsys/wait.hをインクルードすると
以下のエラー文が出ます。
windows環境なためsys/wait.hが使えないのでしょうか。
その場合、必要なインストール方法・gccのオプション指定等もご教授いただければ幸いです。
gcc -pthread .\variablesProc.c -lws2_32 .\variablesProc.c:5:10: fatal error: sys/wait.h: No such file or directory #include <sys/wait.h>
C
1#include <pthread.h> 2#include <unistd.h> 3#include <stdlib.h> 4#include <stdio.h> 5#include <sys/wait.h> 6#include <sys/types.h> 7#define _WIN32_WINNT 0x0501 8#include <winsock2.h> 9 10int varA; 11 12void ProcessFunc(int n){ 13 int varB; 14 15 varB = 4+n; 16 printf("threadFunc-%d-1: varA=%d, varB=%d\n",n,varA,varB); 17 varA = 5+n; 18 printf("threadFunc-%d-2: varA=%d, varB=%d\n",n,varA,varB); 19 sleep(2); 20 printf("threadFunc-%d-3: varA=%d, varB=%d\n",n,varA,varB); 21 varB = 6+n; 22 printf("threadFunc-%d-4: varA=%d, varB=%d\n",n,varA,varB); 23 24 exit(0); 25} 26 27int main(void){ 28 pid_t process1,process2; 29 int varB; 30 31 32 varA = 1; varB = 2; 33 printf("main-1: varA=%d, varB=%d\n",varA,varB); 34 if((process1 = fork()) == 0){ 35 //this is child process 36 processFunc(1); 37 } 38 //this is process 39 sleep(1); 40 varB = 3; 41 42 printf("main-2: varA=%d, varB=%d\n",varA,varB); 43 if((process2 = fork()) == 0){ 44 //this is process 45 processFunc(2); 46 } 47 //this is process 48 waitpid(process1, NULL, 0); 49 waitpid(process2, NULL, 0); 50 printf("main-3: varA=%d, varB=%d\n",varA,varB); 51 52 return 0; 53}

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。