我是靠谱客的博主 慈祥橘子,这篇文章主要介绍linux实验四---管道,现在分享给大家,希望可以做个参考。

#define MSGSIZE 25

main()
{
	int pfd[2],pid;	
	static charmsgsend[MSGSIZE+1]=”Hi!Kid.n”;	
	static charmsgrev[MSGSIZE+1];	
	if(pipe(pfd)==-1)		
	{
		perror(“pipe”);	
		exit(1);	
	}
	if((pid=fork())==0)	
	{	
		puts(“beforeread”);	
		read(pfd[0],msgrev,strlen(msgsend)+1);	
		puts(“readcompletely”);	
		puts(msgrev);	
	}
	else		
	{		
		puts(“Parentsleeping......”);	
		sleep(2);	
		puts(“Parentwakeup......”);	
		write(pfd[1],msgsend,strlen(msgsend)+1);	
	}
	exit(0);	
}


最后

以上就是慈祥橘子最近收集整理的关于linux实验四---管道的全部内容,更多相关linux实验四---管道内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部