#include <stdio.h> #include <process.h> int spawnl(int mode, char *cmd, char *arg0, char *arg1,・・・,char *argn, NULL) mode : 以下のいずれかの値を使用します _P_OVERLAY : 親プロセスを子プロセスでオーバーレイし,親プロセスを破壊 _P_WAIT : 子プロセスの実行が完了するまで親プロセスの実行を一時停止 cmd : 子プロセスとして実行されるファイル名 arg0,・・・ : 引数の並び.通常,arg0 は実行されるファイル名へのポインタです.
#include <stdio.h>
#include <process.h>
int main()
{
char *s[3];
spawnl(_P_WAIT, "test", "test", "data1", NULL);
spawnl(_P_WAIT, "test", "test", "data2", NULL);
s[0] = "test";
s[1] = "data3";
s[2] = NULL;
spawnv(_P_WAIT, "test", s);
s[1] = "data4";
spawnv(_P_WAIT, "test", s);
return 0;
}
以下,子プロセスとして実行されるプログラム(ファイル名:test.exe)
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%s\n", argv[1]);
return 0;
}
data1 data2 data3 data4
| 菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |