第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

作業(yè)社區(qū)

探索學(xué)習(xí)新天地,共享知識(shí)資源!

0 提交作業(yè)
0個(gè) 布置作業(yè)
0 滿分作業(yè)
得分 100
學(xué)習(xí)任務(wù)

不愛(ài)學(xué)習(xí)的那誰(shuí) 的學(xué)生作業(yè):

#include #include #include #include #include #include #include #include #define PATHNAME "." #define PRO_ID 10 #define MSG_TYPE_A 100 #define MSG_TYPE_B 200 #define MSG_SZ 64 // 發(fā)送的 消息結(jié)構(gòu)體 struct msgbuf{ long mtype; char mtext[MSG_SZ]; }; int main(void) { pid_t cpid; key_t key; int msgid, retA, retB; char buffer[MSG_SZ]; ssize_t rbytes; struct msgbuf msgA; struct msgbuf msgB; struct msgbuf rcv_msg; key = ftok(PATHNAME, PRO_ID); if(key == -1){ perror("fotk(): "); exit(EXIT_FAILURE); } msgid = msgget(key, IPC_CREAT | 0666); if(msgid == -1) { perror("msgget(): "); exit(EXIT_FAILURE); } printf("msg id : %d\n",msgid); cpid = fork(); if (cpid == -1) { perror("[ERROR] fork(): "); exit(EXIT_FAILURE); } else if (cpid == 0) { // 子進(jìn)程A while(1) { // 接收消息 rbytes = msgrcv(msgid, (void *)&rcv_msg, MSG_SZ, MSG_TYPE_A, 0); if(rbytes == -1){ perror("[ERROR] msgrcv(): "); exit(EXIT_FAILURE); } printf("進(jìn)程A: mtype : %ld\n", rcv_msg.mtype); printf("進(jìn)程A: mtext : %s\n", rcv_msg.mtext); } } else if (cpid > 0) { // 父進(jìn)程 cpid = fork(); if (cpid == -1) { perror("[ERROR] fork(): "); exit(EXIT_FAILURE); } else if (cpid == 0) { // 子進(jìn)程B while(1) { // 接收消息 rbytes = msgrcv(msgid, (void *)&rcv_msg, MSG_SZ, MSG_TYPE_B, 0); if (rbytes == -1) { perror("[ERROR] msgrcv(): "); exit(EXIT_FAILURE); } printf("進(jìn)程B: mtype : %ld\n", rcv_msg.mtype); printf("進(jìn)程B: mtext : %s\n", rcv_msg.mtext); } } else if (cpid > 0) { // 父進(jìn)程 while (1) { fgets(buffer, sizeof(buffer), stdin); if (strcmp(buffer, "quit") == 0) { printf("GoodBye!\n"); exit(EXIT_SUCCESS); } msgA.mtype = MSG_TYPE_A; // 子進(jìn)程A strcpy(msgA.mtext, buffer); msgB.mtype = MSG_TYPE_B; // 子進(jìn)程B strcpy(msgB.mtext, buffer); // 發(fā)送消息 retA = msgsnd(msgid, (const void *)&msgA, strlen(msgA.mtext) + 1, 0); retB = msgsnd(msgid, (const void *)&msgB, strlen(msgB.mtext) + 1, 0); if (retA == -1 || retB == -1) { perror("msgsnd(): "); exit(EXIT_FAILURE); } } } } return 0; } 【圖片】 【圖片】

微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)