当前位置: 技术问答>linux和unix
如何让程序执行其他的程序
来源: 互联网 发布时间:2015-11-01
本文导语: 我想让程序a 执行程序b 程序a #include #include #include int main(void) { pid_t pid; int status; if((pid=fork())==-1) { printf("Create Child error!"); exit(0); } else if(pid==0) { printf("now is the C...
我想让程序a 执行程序b
程序a
#include
#include
#include
int main(void)
{
pid_t pid;
int status;
if((pid=fork())==-1)
{
printf("Create Child error!");
exit(0);
}
else if(pid==0)
{
printf("now is the Child %d n",getpid());
execl("/root","a.out",(char*)0);
}
else
{
wait(&status);
sleep(2);
printf("now is the Father %d n",getppid());
}
return 1;
}
程序b
#include
int main(void)
{
printf("hello!");
exit(0);
}
我作了n 次就是出现不了b 的结果
希望各位大虾指教
程序a
#include
#include
#include
int main(void)
{
pid_t pid;
int status;
if((pid=fork())==-1)
{
printf("Create Child error!");
exit(0);
}
else if(pid==0)
{
printf("now is the Child %d n",getpid());
execl("/root","a.out",(char*)0);
}
else
{
wait(&status);
sleep(2);
printf("now is the Father %d n",getppid());
}
return 1;
}
程序b
#include
int main(void)
{
printf("hello!");
exit(0);
}
我作了n 次就是出现不了b 的结果
希望各位大虾指教
|
execl("./a.out","a.out");