ChinaUnix.net
相关文章推荐:

fork返回值中没有0

fork()为什么返回两个值? 为什么使子进程得到返回值是0? 谢谢

by VIP_fuck - C/C++ - 2009-06-10 17:19:11 阅读(18925) 回复(35)

相关讨论

#include #include #include"apue.h" #include"unix_err.h" int glob = 6; char buf[] = "a write to stdout\n"; int main() { int var; pid_t pid; pid_t pid_child; var = 88; if(write(STDOUT_FILENO,buf,sizeof(buf)-1) != sizeof(buf)-1) { err_sys("write error"); } printf("before fork\n"); if( (pid=fork()) < 0 ) { err_sys("fork error"); } else if(pid == 0) { if( (...

by fan2290 - C/C++ - 2006-12-21 10:31:59 阅读(3562) 回复(12)

我试了一下可以,想确认一下。。。 如果这样做的话有没有什么问题,需不需要注意什么? 谢谢

by zjpangxie - C/C++ - 2005-02-17 11:48:59 阅读(995) 回复(2)

#include #include #include #include int glob =6; int main(){ int var; pid_t pid; var =88; if((pid=fork()<0)) printf("fork error"); else if(pid==0){ glob++; var++; }else{ sleep(2); } printf("pid=%d,glob=%d,var=%d\n",getpid(),glob,var); } 执行结果,怎么和书上说的严重不一样呀 [lgl@jlu work]$ gcc -o 8 8...

by redog - C/C++ - 2005-11-05 15:57:22 阅读(1533) 回复(10)

主函数main()里面有一个while(1)的循环,每隔1秒fork()一次,子进程打印一串字符之后调用exit(0),父进程继续loop。但是从ps看系统的进程状态,发现有好多同名字的进程,这是为什么阿,子进程应该如何退出阿?谢谢!

by yangruqing - C/C++ - 2008-11-07 13:17:32 阅读(2420) 回复(5)

#include ; #include ; #include ; #include ; void main() { if (fork() == 0) sleep(10); else exit(0); } test15:/usr/tux/zp/tmp $ cc -o zomb test.c test15:/usr/tux/zp/tmp $ ./zomb test15:/usr/tux/zp/tmp $ ps -ef|grep zomb tux 8160 8030 0 15:15:13 pts/ti 0:00 grep zomb tux 8158 1 0 15:15:...

by tom2zhang - C/C++ - 2005-04-28 12:55:39 阅读(1616) 回复(10)

c++写了一个程序,生成了一个线程,而后在该线程中调用fork生成一个子进程来执行 perl脚本(该脚本执行正确),父进程在一个循环中调用waitpid非阻塞的查看子进程状态,等待子进程退出。 结果发现父进程无法正常的得到子进程的结束状态,waitpid开始返回是0,在子进程结束后, 父进程返回的是-1. 请问这是什么原因,在线程中再生成进程会有什么问题么?

by chesterlk - C/C++ - 2007-01-14 10:51:46 阅读(2270) 回复(2)

先 fork 子进程然后 execl 另一个可执行程序, 如何得到这个可执行程序结束的返回值?

by zxcdewq - C/C++ - 2006-03-30 15:08:52 阅读(1553) 回复(1)

pid_t pid; int stat_loc; /*父进程*/ if ((pid=fork())>0) { waitpid(pid,&stat_loc,0); /*父进程等待进程号为pid的子进程的返回*/ } else { /*子进程的处理过程*/ exit(1); } /*父进程*/ printf("stat_loc is [%d]\n",stat_loc);

by dida_327 - 内核/嵌入技术 - 2005-12-16 09:10:58 阅读(8040) 回复(5)

这是【FreeBSD操作系统设计与实现】的习题5.5,原文如下: 5.5 Explain why the vfork system call will always be more efficient than a clever implementation of the fork system call.

by 雨丝风片 - BSD - 2006-03-29 20:58:05 阅读(4079) 回复(8)

apue中8-1的例子,(第一版与第二版 皆可) myfork.c --------------------------------------------------------------------------- #include "apue.h" int glob=6; char buf[]=" a write to stdout\n"; int main(int argc, char *argv[]) { int var; pid_t pid; var=88; if(write(STDOUT_FILENO,buf,sizeof(buf)-1)!=sizeof(buf)-1) err_sys("write error"); prin...

by sunshine217 - C/C++ - 2009-01-17 22:41:34 阅读(1570) 回复(8)