当前位置: 技术问答>linux和unix
父进程结束了,子进程运行会出错?
来源: 互联网 发布时间:2016-05-27
本文导语: 该程序 大概是 pid_t pid; char str[30]; int main() while((pid=fork())!=0); if(pid==0) { printf("输入:"); gets(str); while(strcmp(str,"end")!=0) { func(str); //对字符串作处理 printf("...
该程序 大概是
pid_t pid;
char str[30];
int main()
while((pid=fork())!=0);
if(pid==0)
{
printf("输入:");
gets(str);
while(strcmp(str,"end")!=0)
{
func(str); //对字符串作处理
printf("输入:");
gets(str);
}
}
else
{
waitpid(pid,NULL,0); //当没有这句时,出错,不停的输出"输入:"
return ;
}
哪位能给解释下,谢谢
pid_t pid;
char str[30];
int main()
while((pid=fork())!=0);
if(pid==0)
{
printf("输入:");
gets(str);
while(strcmp(str,"end")!=0)
{
func(str); //对字符串作处理
printf("输入:");
gets(str);
}
}
else
{
waitpid(pid,NULL,0); //当没有这句时,出错,不停的输出"输入:"
return ;
}
哪位能给解释下,谢谢
|
Bugs
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.