Created
June 12, 2020 04:21
-
-
Save redatawfik/c4433d5b6a19c3525f7e022cc6b9a318 to your computer and use it in GitHub Desktop.
Server implementation for POSIX client-server program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/ipc.h> | |
#include <sys/shm.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define SIZE 2 | |
int main() { | |
int shmid; | |
key_t key; | |
char *shm, *s; | |
key = 5678; | |
shmid = shmget(key, SIZE, IPC_CREAT | 0666); | |
shm = shmat(shmid, NULL, 0); | |
s = shm; | |
*s = '-'; | |
*s++; | |
*s = '1'; | |
*s++; | |
*s = NULL; | |
while (1) { | |
sleep(1); | |
if (*shm != '7') { | |
s = shm; | |
*s = '-'; | |
*s++; | |
*s = '1'; | |
*s++; | |
*s = NULL; | |
} else { | |
exit(0); | |
} | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment