差分

移動先: 案内検索

プロセス管理

129 バイト除去, 2022年2月17日 (木) 04:32
プロセスの生成は[http://man7.org/linux/man-pages/man2/fork.2.html fork(2)]を使い親プロセスが子プロセスを生み出します。下のコードを見て下さい。
 <syntaxhighlight langpre class='"C' line="1" >
#include <unistd.h>
#include <stdlib.h>
return(0);
}
</syntaxhighlight pre >
システムコールfork(2)はフォーク後、親プロセスでは子プロセスのプロセスIDを返却し、子プロセスでは0を返却します。
<syntaxhighlight langpre class='"C' line="1" >
#include <unistd.h>
#include <sys/types.h>
wait(&wstat);
}
</syntaxhighlightpre>
* fork版
<syntaxhighlight langpre class='"C' line="1" >
#include <sys/types.h>
#include <unistd.h>
printf("%d\n",i);
}
</syntaxhighlightpre
<pre class="bash">
% cc -O fork.c -o f
* thread版
<syntaxhighlight langpre class='"C' line="1" > 
#include <pthread.h>
#include <stdlib.h>
printf("%d\n",i);
}
</syntaxhighlightpre>
<pre class="bash">
% cc -O thread.c -lpthread -o t