以下是我的代码使用和在shell脚本和进程创建在Unix中
main(int argc, char **argv){
char *MyName=argv[1];
int cpid=fork();
if(cpid==0){
printf("The Child is %s of %d\n",MyName,getpid());
exit(0);
}
else{
printf("My child is %d\n",cpid);
exit(0);
}
}
现在我正在写一个shell脚本来运行后援以下是我的shell脚本
#!/bin/sh
clear
gcc arg.c
for((i=1;i<=5;i++))
do
./a.out Invocation$i
done
输出是
My child is 28629
My child is 28631
The Child is Invocation1 of 28629
My child is 28633
The Child is Invocation2 of 28631
My child is 28635
The Child is Invocation3 of 28633
My child is 28637
The Child is Invocation4 of 28635
The Child is Invocation5 of 28637
但是,如果我在脚本把&
Invocation$i
后然后输出
My child is 29158
My child is 29159
My child is 29160
My child is 29161
The Child is Invocation4 of 29159
The Child is Invocation5 of 29158
The Child is Invocation3 of 29160
The Child is Invocation2 of 29161
My child is 29163
The Child is Invocation1 of 29163
能否请您解释一下这两个输出和使用&之间的差异。
如果我想通过每一个叉方法创建的各个过程,以开始下一个
是否有关于您试图了解的输出的具体问题?你知道shell中的'&'是什么吗? –
其实他们都是。但主要是为什么输出是不同的。 –
您的文本编辑器是否损坏?你的代码示例看起来非常难看。 – hek2mgl