Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
フォークで最初に何が実行されるかわかりません。たとえば、次のコードがあります。
int main() { int n = 1; if(fork() == 0) { n = n + 1; exit(0); } n = n + 2; printf(“%d: %d\n”, getpid(), n); wait(0); return 0; }
これは画面に何を出力しますか?
1: 3 0: 4
また
0: 4 1: 3
あるプロセスを他のプロセスより先に実行させたい場合は、sleep() システム コールを使用してみてください。