产卵一个独立的孩子 [英] Spawn an independent child

查看:150
本文介绍了产卵一个独立的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何可以使用C产卵一个独立的子进程处理其业务,而不用考虑孩子的父亲?

How can you use C to spawn an independent child process that goes about its business without thinking about the father?

我要产卵多个进程,他们已经建立后不久,他们去做好自己的工作之前,他们睡了约2分钟。

I want to spawn several processes and shortly after they have been created they go to sleep for about 2 minutes before they do their job.

不过,我不希望父亲等到孩子在我要产卵了多个进程同时因为完成了。

However, I don't want the father to wait until the child is finished because in the meantime I want to spawn off more processes.

我在Linux上。

推荐答案

使用fork()。
叉()系统调用

pid_t pid = fork (); 
if (pid < 0) 
  // Error
else if (pid == 0) 
  // Child Process
  // Sleep 2 min. ?!
else 
  // Code for Father

这篇关于产卵一个独立的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆