ASS7
ASS7
CLIENT.C Program
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
int main() {
int shmid;
char *shm_ptr;
if (shmid < 0) {
perror("shmget failed");
exit(1);
perror("shmat failed");
exit(1);
while (shm_ptr[SHM_SIZE - 1] != 1) {
// Busy wait
shmdt(shm_ptr);
return 0;
SERVER.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <unistd.h>
int main() {
int shmid;
char *shm_ptr;
if (shmid < 0) {
perror("shmget failed");
exit(1);
}
// Attach to the shared memory segment
perror("shmat failed");
exit(1);
while (shm_ptr[SHM_SIZE - 1] == 1) {
// Cleanup
shmdt(shm_ptr);
return 0;
}
OUTPUT:-