当前位置: 技术问答>linux和unix
执行系统命令问题
来源: 互联网 发布时间:2016-10-11
本文导语: 假如 int i = 0; while(...) { fp = fopen("1.log", "a+"); system("ls"); fprintf(fp, "%dn", &i); sleep(1); flose(fp); i++; } 有没有可能在1.log中出现两个相同的i 例如: 1 2 2 3 4 5 6 system函数fork的...
假如
int i = 0;
while(...)
{
fp = fopen("1.log", "a+");
system("ls");
fprintf(fp, "%dn", &i);
sleep(1);
flose(fp);
i++;
}
有没有可能在1.log中出现两个相同的i
例如:
1
2
2
3
4
5
6
system函数fork的进程是何时退出的?
int i = 0;
while(...)
{
fp = fopen("1.log", "a+");
system("ls");
fprintf(fp, "%dn", &i);
sleep(1);
flose(fp);
i++;
}
有没有可能在1.log中出现两个相同的i
例如:
1
2
2
3
4
5
6
system函数fork的进程是何时退出的?
|
fprintf(fp, "%dn", &i); //有问题吧,怎么把i的地址写入文件??
如果只有一个进程的话,不会出现重复的i
system函数fork的进程在system返回之前退出
如果只有一个进程的话,不会出现重复的i
system函数fork的进程在system返回之前退出
|
int main(int argc, char* argv[]) {
pid_t pid;
char line[1000];
int status;
while (cin.getline(line,'n')){
if((pid=fork())