A signal is used in the UNIX system to notify a process that a particular event has occurred. A signal may be received either synchronously or asynchronously depending on the source and the reason for the event being signalled. A signal must follow the following pattern –
1. A signal is generated by the occurrence of a particular event.
2. A generated signal is delivered to a particular process.
3. The signal must be handled after receiving at the process.
In this problem, the message is sent from one user to another user using kill function. kill function takes two inputs – process id of the receiver process and signal type. For this purpose, we use a shared memory where we store the process id(s) of two processes. We use a handler function which will print the message received from another process. User2 will start to send message to User1 and then they will continue chatting.
#define FILLED 0
#define Ready 1
#define NotReady -1
intstatus, pid1, pid2;
// handler function to print message received from user2
// if signum is SIGUSR1, then user 1 is receiving a message from user2
Please Login to comment...