GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — spo/lab6_spo.c at master · TheLester/spo Expand file tree/ Copy pathlab6_spo.cMore file actions 56 lines (52 loc) · 1.22 KB / Copy pathlab6_spo.cFile metadata and controls56 lines (52 loc) · 1.22 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 /* ============================================================================ Name : lab6_spo.c Author : Lester Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <fcntl.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> #include <sys/sem.h> int pid2; int msgid; key_t key; int x; //for waiting struct pid_msgbuf { long mtype; int pid; }; int main(void) { key = ftok("/home/lester/soft/test", 'S'); msgid = msgget(key, 0666 | IPC_CREAT); int size = sizeof(struct pid_msgbuf) - sizeof(long); pid2 = fork(); if (pid2 == 0) { //process2 struct pid_msgbuf pmb = { 2, getpid() }; msgsnd(msgid, &pmb, size, 2); struct pid_msgbuf pmb_recv; sleep(1); msgrcv(msgid, &pmb_recv, size, 1, 0); printf("%d \n", pmb_recv.pid); exit(0); } pid3 == fork(); if(pid3 == 0){ struct pid_msgbuf pmb_recv; struct pid_msgbuf pmb = { 1, getpid() }; msgsnd(msgid, &pmb, sizeof(int), 1); msgrcv(msgid, &pmb_recv, size, 2, 0); printf(" %d \n", pmb_recv.pid); wait(NULL); msgctl(msgid, IPC_RMID, NULL); exit(0); } sleep(2); wait(NULL); exit(0); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |