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

📄 process_1.c

📁 linux下模拟进程互斥的一个小程序。
💻 C
字号:
/* process_1.c */#include "msgcom.h"main(){  int a,b,m,qid;  struct msgtype buf;  buf.mtype=1;  buf.text.appli_in=0;  buf.text.appli_exit=0;  qid=msgget(MSGKEY,IPC_CREAT|0666);  printf (" *Process_1 request into eritical_sect !\n" );  printf("    ------If other process using the eritical_sect ,must wait !\n ");    msgsnd ( qid, &buf, sizeof(buf.text), 0 );  msgrcv ( qid, &buf, 512, 2, MSG_NOERROR );    if ( buf.text.appli_in==1 ) {     printf ( " *The process_1 is in the eritical_sect !\n" );          /* my program */     printf ( " *Please input the vaule of a:");     scanf ( "%d",&a );     printf ( " *Please input the vaule of b:");      scanf ( "%d",&b );     m=a+b;     printf ( " *THE RESULT IS : m=a+b=%d\n",m );                printf ( " *The process_1 is request to leave eritical_sect !\n" );     buf.text.appli_exit=1;     buf.mtype=3;     msgsnd( qid, &buf, sizeof(buf.text), 0 );     msgrcv( qid, &buf, 512, 4, MSG_NOERROR );     printf ( " *The process_1 have left eritical_sect ! \n");  }      }

⌨️ 快捷键说明

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