fork函数超详解及其用法.docVIP

  • 9
  • 0
  • 约1.03万字
  • 约 18页
  • 2017-10-31 发布于河南
  • 举报
fork函数超详解及其用法.docfork函数超详解及其用法.doc

3. 进程控制 上一页 第 30 章 进程 下一页 3. 进程控制 3.1. fork函数 #include sys/types.h #include unistd.h pid_t fork(void); fork调用失败则返回-1,调用成功的返回值见下面的解释。我们通过一个例子来理解fork是怎样创建新进程的。 例 30.3. fork #include sys/types.h #include unistd.h #include stdio.h #include stdlib.h int main(void) { pid_t pid; char *message; int n; pid = fork(); if (pid 0) { perror(fork failed); exit(1); } if (pid == 0) { message = This is the child\n; n = 6; } else { message = This is the parent\n; n = 3; } for(; n 0; n--) { printf(message);

文档评论(0)

1亿VIP精品文档

相关文档