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

📄 xoxo.c

📁 three proceses , one proces read some mesages entered from the keyboard until read s EXIT, the the s
💻 C
字号:
#include <stdio.h>       #include <sys/types.h>       #include <unistd.h>#include <sys/ipc.h>#include <sys/shm.h>#include <string.h>#define SHMSZ     27int main(){	int shmid;	int *shm;	key_t key;	key =ftok("./",1);	if((shmid=shmget(key,SHMSZ,IPC_CREAT | 0666))<0){		perror("shmget");		return 1;	}	if ((shm=shmat(shmid,NULL,0))==(int *) -1){		perror("shmat");		return 1;	}		*shm=0;switch(fork()){	case -1: {		perror("eroare fork\n");		break;		}	case 0:{ 		printf("%d - fiu\n",getpid());		switch(fork()){		case -1: {			perror("eroare fork\n");			break;			}		case 0:{ 			printf("%d - nepot\n",getpid());			char *str;			strcpy(str,"GOL");			while (strcmp(str,"EXIT")!=0)			{				printf("mesaj \n");				scanf("%s",str);			}			int nepot_id=getpid();			*shm=nepot_id;						break;			}		default:{			//fiuuuuuuuuuuuuuuuuuuuuuuuuuuuu			char *u;			while (*shm == 0)				sleep(1);			kill(*shm,9);			printf("nepot killarit la pid %d \n",*shm);			*shm=getpid();			kill(getpid(),9);		//	printf("tata homorat \n");			break;			}		}		break;		}	default:{		printf("%d - tata\n",getpid());		sleep(2);		/*if (*shm!=0)		printf("tata killarit la pid %d \n",*shm);	*/	break;		}}sleep(10);return 0; }

⌨️ 快捷键说明

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