C语言 求该程序的输出结果
通过一个进程使用fork函数创建一个子进程,然后通过无名管道从子进程向父进程发送数据“父亲你在吃火锅吗?”#include<stdio.h>#include<unistd...
通过一个进程使用fork函数创建一个子进程,然后通过无名管道从子进程向父进程发送数据“父亲你在吃火锅吗?”
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
void main()
{
int fd[2] = {0};
pid_t pid = 0;
char buf[100] = {0};
char string_data[100] = "父亲你在吃火锅吗?";
pipe(fd); //创建无名管道
pid = fork(); //创建子进程*
if (pid == 0)
{
close(fd[0]);
write(fd[1], string_data, strlen(string_data));
exit(0);
}
else if (pid > 0){
close(fd[1]);
read(fd[0], buf, strlen(string_data));
printf("我是父亲进程,我收到了来自儿子的数据:%s/n",buf);
}
else
{
printf(“创建进程失败\n!”);
}
exit(0);
} 展开
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
void main()
{
int fd[2] = {0};
pid_t pid = 0;
char buf[100] = {0};
char string_data[100] = "父亲你在吃火锅吗?";
pipe(fd); //创建无名管道
pid = fork(); //创建子进程*
if (pid == 0)
{
close(fd[0]);
write(fd[1], string_data, strlen(string_data));
exit(0);
}
else if (pid > 0){
close(fd[1]);
read(fd[0], buf, strlen(string_data));
printf("我是父亲进程,我收到了来自儿子的数据:%s/n",buf);
}
else
{
printf(“创建进程失败\n!”);
}
exit(0);
} 展开
1个回答
展开全部
printf("我是父亲进程,我收到了来自儿子的数据:%s/n",buf);
//你这里输错了吧?/n应该是\n吧?
//你这里输错了吧?/n应该是\n吧?
更多追问追答
追问
嗯嗯这代码是有错的可以帮我看下哪里吗
还有可以告诉我运行结果吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询