⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipe.c

📁 word count information using message queues
💻 C
字号:
//ONE CONSUMER  ONE PRODUCER #include<stdio.h>#include<unistd.h>#include<stdlib.h>#include<string.h>int main(){char msgs[200],msgr[200];// printf("sayooj \n");// fgets(msg,sizeof(msg),stdin);// printf(" the message is : %s",msg); int ch=1;int p[2],pid;if(pipe(p)==-1)	{	printf("some error in creating pipe ");	}else	{	printf("pipe has been creted successfully \n");	}pid=fork();while(ch<7){if(pid==0)	{		//child consumer	close(p[1]);	if(read(p[0],msgr,sizeof(msgr))==-1)		{		printf("error in reading \n");		}	else		{		printf("message received by child : %s",msgr);		fflush(stdout);		sleep(5);		//to make child slower 		ch++;		}	}else	{		//parent producer	close(p[0]);	printf("enter the message \n");	fgets(msgs,sizeof(msgs),stdin);	if(write(p[1],msgs,sizeof(msgs))==-1)		{		printf("error in writing \n");		}	else		{		printf("message sent by parent is : %s",msgs);		fflush(stdout);		}		}// scanf("enter %d",&ch);}return 0 ;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -