我在c languge中创建了一个小程序。该程序使用fork()函数创建了一些子程序。创建的程序的数量作为第一个参数控制台。我希望有人帮助我将这个程序从c转换为bash脚本。将程序从c转换为bash脚本
/* The first argument is the amount of the procceses to be created*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main(int argc, char **argv)
{
int pid,i;
int pnumber;
pnumber=atoi(argv[1]);//Converting the first arg to int so i can put in for loop
for(i=1;i<=pnumber;i++){
pid=fork();// Creating the child procceses with fork
if(pid!=0) { //The child procces prints its id and then exit
printf("The id the created proccess is:%d and it is a child proccess \n",pid);
printf("RETURN\n");
exit(1);
}
}
}
你到目前为止有什么? – mdm 2010-04-06 13:45:52
如果你丢弃代码,那么它并不重要,但是对fork()返回的检查看起来不正确,应该是子节点的'(pid == 0)'。 – Hasturkun 2010-04-06 14:12:20