Skip to content

Instantly share code, notes, and snippets.

@redatawfik
Created June 12, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redatawfik/c4433d5b6a19c3525f7e022cc6b9a318 to your computer and use it in GitHub Desktop.
Save redatawfik/c4433d5b6a19c3525f7e022cc6b9a318 to your computer and use it in GitHub Desktop.
Server implementation for POSIX client-server program
#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