Experiment 8
Experiment 8
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(){
char buffer[20];
mkfifo("my_Pipe", 0666);
pid=fork();
//Parent Section
fd1=open("my_Pipe", O_WRONLY);
if(pid==0){
//Child section
fd2=open("my_Pipe", O_RDONLY);
printf("%s", buffer);
}
return 0;
Output:
Code:
Q2.Establish Interprocess communication (IPC) using message passing
technique.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
struct message {
long msg_type;
char msg_text[100];
};
int main() {
key_t key;
int msgid;
if (msgid == -1) {
perror("msgget");
exit(EXIT_FAILURE);
if (child_pid == -1) {
perror("fork");
exit(EXIT_FAILURE);
if (child_pid == 0) {
// Child process
} else {
// Parent process
msg.msg_type = 1;
return 0;
Output:
Q3.Establish Interprocess communication (IPC) Message queue Technique.
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
struct message {
long msg_type;
char msg_text[100];
};
int main() {
key_t key;
int msgid;
msg.msg_type = 1;
perror("msgsnd");
exit(EXIT_FAILURE);
}
printf("Message sent: %s\n", msg.msg_text);
perror("msgrcv");
exit(EXIT_FAILURE);
perror("msgctl");
exit(EXIT_FAILURE);
return 0;
Output:
Code:
Submitted By Submitted to
MEDHANSH ALOK ASHISH SIR
VARSHA