22BCE1726 Chat Application
22BCE1726 Chat Application
Instructions
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#define FILLED 0
#define Ready 1
#define NotReady -1
struct memory {
char buff[100];
};
if (signum == SIGUSR1) {
puts(shmptr->buff); }
int main()
// process id of user1
int shmid;
// key value of shared memory
shmptr->pid1 = pid;
shmptr->status = NotReady;
signal(SIGUSR1, handler);
while (1) {
continue;
sleep(1);
printf("User1: ");
shmptr->status = FILLED;
kill(shmptr->pid2, SIGUSR2);
shmdt((void*)shmptr);
return 0;
}
CODE FOR USER2:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#define FILLED 0
#define Ready 1
#define NotReady -1
struct memory {
char buff[100];
};
if (signum == SIGUSR2) {
puts(shmptr->buff);
// main function
int main()
// process id of user2
shmptr->pid2 = pid;
shmptr->status = NotReady;
signal(SIGUSR2, handler);
while (1) {
sleep(1);
printf("User2: ");
shmptr->status = Ready;
kill(shmptr->pid1, SIGUSR1);
continue;
shmdt((void*)shmptr);
return 0;
}
Output: