This commit is contained in:
p-w-rs
2022-09-21 12:04:48 -05:00
parent 9e1ad48346
commit 6d881b3edd
75 changed files with 3681 additions and 113 deletions

Binary file not shown.

View File

@@ -0,0 +1,39 @@
// C Program for Message Queue (Reader Process)
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
// structure for message queue
struct mesg_buffer
{
long mesg_type;
char mesg_text[100];
} message;
int main()
{
key_t key;
int msgid;
// ftok to generate unique key
key = ftok("progfile", 65);
// msgget creates a message queue
// and returns identifier
msgid = msgget(key, 0666 | IPC_CREAT);
// msgrcv to receive message
msgrcv(msgid, &message, sizeof(message), 0, 0);
printf("Data Received is : %s \n", message.mesg_text);
msgrcv(msgid, &message, sizeof(message), 0, 0);
printf("Data Received is : %s \n", message.mesg_text);
msgrcv(msgid, &message, sizeof(message), 0, 0);
printf("Data Received is : %s \n", message.mesg_text);
msgrcv(msgid, &message, sizeof(message), 0, 0);
printf("Data Received is : %s \n", message.mesg_text);
// to destroy the message queue
msgctl(msgid, IPC_RMID, NULL);
return 0;
}

View File

@@ -0,0 +1,46 @@
// C Program for Message Queue (Writer Process)
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MAX 10
// structure for message queue
struct mesg_buffer
{
long mesg_type;
char mesg_text[100];
} m1, m2, m3, m4;
int main()
{
key_t key;
int msgid;
// ftok to generate unique key
key = ftok("progfile", 65);
// msgget creates a message queue
// and returns identifier
msgid = msgget(key, 0666 | IPC_CREAT);
m1.mesg_type = 1;
m2.mesg_type = 2;
m3.mesg_type = 3;
m4.mesg_type = 4;
printf("Write Data : ");
fgets(m1.mesg_text, MAX, stdin);
fgets(m2.mesg_text, MAX, stdin);
fgets(m3.mesg_text, MAX, stdin);
fgets(m4.mesg_text, MAX, stdin);
// msgsnd to send message
msgsnd(msgid, &m1, sizeof(m1), 0);
msgsnd(msgid, &m2, sizeof(m2), 0);
msgsnd(msgid, &m3, sizeof(m3), 0);
msgsnd(msgid, &m4, sizeof(m4), 0);
// display the message
// printf("Data send is : %s \n", message.mesg_text);
return 0;
}

View File

@@ -3,12 +3,12 @@
* to send a signal from one process to another
*/
#include <signal.h> // needed for signal system call
#include <stdio.h> // needed for printf, perror
#include <stdlib.h> // needed for exit
#include <sys/types.h> // needed for pid_t
#include <sys/wait.h> // needed for wait system call
#include <unistd.h> // needed for fork, getpid, getppid, kill system calls
#include <stdlib.h> // needed for exit
#include <signal.h> // needed for signal system call
#include <stdio.h> // needed for printf, perror
void signal_handler(int sig)
{
@@ -23,12 +23,12 @@ int main()
pid_t pid = fork(); // fork into 2 processes
if(pid < 0) // error
if (pid < 0) // error
{
perror("fork");
exit(EXIT_FAILURE);
}
else if(pid == 0) // child
else if (pid == 0) // child
{
// Send a signal to the parent by its PID
pid_t parent_pid = getppid();

BIN
Examples/ipc/rec Executable file

Binary file not shown.

BIN
Examples/ipc/send Executable file

Binary file not shown.