国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

QY

2023-03-10 21:56 作者:神隱的千尋バ  | 我要投稿

//two
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
?#include"P.h"
?#include"P2.h"
#define SEM_READ 0
#define SEM_WRITE 1

union semun
{
?? ?int val;
};
?
void P_operation(int index, int semId);

?
void V_operation(int index, int semId);

?
?

void P2_operation(int index, int semId);

?
void V2_operation(int index, int semId);

?
int main()
{
?? ?key_t key;
?? ?key = ftok("b.c", 123); // 獲取 key 值
?? ?pid_t pid;
?? ?int semId; // 信號燈 ID
?? ?int shmId; // 共享內存 ID
?? ?int semId2; // 信號燈 ID2

?
?? ?char *shamaddr;
?
??? ?semId2 = semget(key, 2, IPC_CREAT | 0755); // 創(chuàng)建信號量
?? ?if (semId < 0)
?? ?{
?? ??? ?perror("semget error");
?? ??? ?return -1;
?? ?}
?? ?semId = semget(key, 2, IPC_CREAT | 0755); // 創(chuàng)建信號量
?? ?if (semId < 0)
?? ?{
?? ??? ?perror("semget error");
?? ??? ?return -1;
?? ?}
?? ?shmId = shmget(key, 128, IPC_CREAT | 0755); // 創(chuàng)建共享內存
?? ?if (shmId < 0)
?? ?{
?? ??? ?perror("shmget error");
?? ??? ?return -1;
?? ?}
?
?? ?// Init semaphore
?? ?union semun myun;
?? ?// Init semaphore read
?? ?myun.val = 0;
?? ?semctl(semId, SEM_READ, SETVAL, myun); // 對 SEM_READ 信號量設置初始值
?? ?// Init semaphore write
?? ?myun.val = 1;
?? ?semctl(semId, SEM_WRITE, SETVAL, myun); // 對 SEM_WRITE 信號量設置初始值
?
?? ?pid = fork();
?
?? ?// child process
?? ?if (pid == 0)
?? ?{
?? ??? ?while (1)
?? ??? ?{
?? ??? ??? ?shamaddr = (char *)shmat(shmId, NULL, 0);
?? ??? ??? ?//printf("Na Hua Yan Dan Ji Xu Kan Bing %s\n", shamaddr); // 操作對共享資源?? ?
?? ??? ??? ?//printf("Hua Yan Wan\n");
?? ??? ??? ?//printf("Qing Xian Hua Yan\n");
?? ??? ??? ?//?? ?printf("Kan Wan Le Xia Yi Wei\n");
?? ??? ??? ?//V2_operation(SEM_WRITE, semId2);?? ??? ?// 共享內存映射
?? ??? ??? ?P_operation(SEM_READ, semId);?? ??? ??? ??? ??? ?// P 操作
?? ??? ??? ?//printf("XIAN HUA YAN: %s\n", shamaddr); // 操作對共享資源
?? ??? ??? ?printf("Hua Yan Wan\n");
?? ??? ?V2_operation(SEM_WRITE, semId2);
?? ??? ?printf("Na Hua Yan Dan Ji Xu Kan Bing\n"); ?? ?
?? ??? ??? ??? ??? ??? ?// V 操作
?? ??? ??? ??? ??? ??? ?printf("Kan Wan Le Xia Yi Wei %s\n", shamaddr);
?? ??? ??? ??? ??? ?
?? ??? ?}
?? ?}
?
?? ?// parent process
?? ?else if (pid > 0)
?? ?{
?? ??? ?while (1)
?? ??? ?{
?? ??? ??? ?shamaddr = (char *)shmat(shmId, NULL, 0);
?? ??? ??? ?
?? ??? ??? ?V_operation(SEM_READ, semId);
?? ??? ??? ?fgets(shamaddr, 32, stdin);
?? ??? ??? ?printf("Qing Xian Hua Yan\n");
?? ??? ??? ?//P_operation(SEM_WRITE, semId);
?? ??? ??? ?//printf("HUA YAN le,kan YI SHENG\n");
?? ??? ??? ?//fgets(shamaddr, 32, stdin);
?? ??? ??? ?
?? ??? ??? ??? ?P2_operation(SEM_WRITE, semId2);
?? ??? ??? ??? ??? ?
?? ??? ?}
?? ?}
?
?? ?return 0;
}






//ww
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
void P_operation(int index, int semId)
{
?? ?struct sembuf sop;
?? ?sop.sem_num = index; //信號燈編號
?? ?sop.sem_op = -1;?? ? // P 操作
?? ?sop.sem_flg = 0;?? ? // 阻塞
?? ?semop(semId, &sop, 1);
}
?
void V_operation(int index, int semId)
{
?? ?struct sembuf sop;
?? ?sop.sem_num = index; //信號燈編號
?? ?sop.sem_op = 1;?? ??? ? // V 操作
?? ?sop.sem_flg = 0;?? ? // 阻塞
?? ?semop(semId, &sop, 1);
}
?




//WW:
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
void P2_operation(int index, int semId)
{
?? ?struct sembuf sop2;
?? ?sop2.sem_num = index; //信號燈編號
?? ?sop2.sem_op = -1;?? ? // P 操作
?? ?sop2.sem_flg = 0;?? ? // 阻塞
?? ?semop(semId, &sop2, 1);
}
?
void V2_operation(int index, int semId)
{
?? ?struct sembuf sop2;
?? ?sop2.sem_num = index; //信號燈編號
?? ?sop2.sem_op = 1;?? ??? ? // V 操作
?? ?sop2.sem_flg = 0;?? ? // 阻塞
?? ?semop(semId, &sop2, 1);
}

QY的評論 (共 條)

分享到微博請遵守國家法律
襄城县| 麻城市| 始兴县| 南通市| 沂南县| 精河县| 建水县| 故城县| 巴马| 石屏县| 湖口县| 宿州市| 赤水市| 通辽市| 兰坪| 宜君县| 寿阳县| 贵阳市| 陵水| 兴业县| 麟游县| 江城| 龙江县| 彭阳县| 荃湾区| 都匀市| 大宁县| 蛟河市| 石台县| 宜兰县| 司法| 绥中县| 喀喇沁旗| 天峨县| 常德市| 郯城县| 开封市| 依兰县| 慈利县| 肥东县| 年辖:市辖区|