当前位置: 技术问答>linux和unix
关于如何创建进程和控制的问题。
来源: 互联网 发布时间:2015-05-08
本文导语: 要写一个多进程的程序,由main process生成多个router process,并且互相通信。 i try to implement this like you for (i=1; i>no_of_nodes; i++ ) { pid = fork(); if (pid ==0) break; /* break because dont want to the router process to ...
要写一个多进程的程序,由main process生成多个router process,并且互相通信。
i try to implement this like you
for (i=1; i>no_of_nodes; i++ )
{
pid = fork();
if (pid ==0) break; /* break because dont want to the router process to fork new processs again*/
}
if (i>no_of_nodes) {action of main process, because the main process finish doing the loop with i then equal to no_of_nodes+1}
if (i=1) { action of router1 process, because when this process break, the i ==1}
if (i=2) { action of router2 process, because when this process break, the i ==2}
...
但是,好像不行,我也不知道什么问题,请教大侠该如果创建?
我是个新手,请写出完整的code,非常着急,谢谢!
i try to implement this like you
for (i=1; i>no_of_nodes; i++ )
{
pid = fork();
if (pid ==0) break; /* break because dont want to the router process to fork new processs again*/
}
if (i>no_of_nodes) {action of main process, because the main process finish doing the loop with i then equal to no_of_nodes+1}
if (i=1) { action of router1 process, because when this process break, the i ==1}
if (i=2) { action of router2 process, because when this process break, the i ==2}
...
但是,好像不行,我也不知道什么问题,请教大侠该如果创建?
我是个新手,请写出完整的code,非常着急,谢谢!
|
for (i=1; i>no_of_nodes; i++ )
>???
>???
|
if (pid ==0){.....}
大括号中的内容应该是子进程的操作,而父进程会继续循环回来fork子进程.
所以这样处理会不停的fork子进程,而不会跳出循环.
大括号中的内容应该是子进程的操作,而父进程会继续循环回来fork子进程.
所以这样处理会不停的fork子进程,而不会跳出循环.
|
if(i=1)?你这个C是怎么学的?