当前位置: 技术问答>linux和unix
多进程编程fork()的问题
来源: 互联网 发布时间:2017-05-03
本文导语: 源程序是这样(编译环境在ubuntu13.10) #include #include #include #include #include int main(void) { pid_t child1, child2, child; child1 = fork(); child2 = fork(); if(child1 == -1) { printf("Child1 fork errorn"); exit(1); } else if(child1 == 0)...
源程序是这样(编译环境在ubuntu13.10)
#include
#include
#include
#include
#include
int main(void)
{
pid_t child1, child2, child;
child1 = fork();
child2 = fork();
if(child1 == -1)
{
printf("Child1 fork errorn");
exit(1);
}
else if(child1 == 0)
{
printf("In child1:execute 'ls -l'n");
if(execlp("ls", "ls", "-l", NULL)
#include
#include
#include
#include
#include
int main(void)
{
pid_t child1, child2, child;
child1 = fork();
child2 = fork();
if(child1 == -1)
{
printf("Child1 fork errorn");
exit(1);
}
else if(child1 == 0)
{
printf("In child1:execute 'ls -l'n");
if(execlp("ls", "ls", "-l", NULL)