Write a C program to create a message queue with read and Write permissions to Write 3 messages to it with different priority numbers.
AIM:
Write a C program to create a message queue with read and write permissions to write 3 messages to it with different priority numbers.
Program:
#include <stdio.h> #include <sys/ipc.h> #include <fcntl.h> #define MAX 255 struct mesg { long type; char mtext[MAX]; } *mesg; char buff[MAX]; main() { int mid,fd,n,count=0;; if((mid=msgget(1006,IPC_CREAT | 0666))<0) { printf(“\n Can’t create Message Q”); exit(1); } printf(“\n Queue id:%d”, mid); mesg=(struct mesg *)malloc(sizeof(struct mesg)); mesg ->type=6; fd=open(“fact”,O_RDONLY); while(read(fd,buff,25)>0) { strcpy(mesg ->mtext,buff); if(msgsnd(mid,mesg,strlen(mesg ->mtext),0)== -1) printf(“\n Message Write Error”); } if((mid=msgget(1006,0))<0) { printf(“\n Can’t create Message Q”); exit(1); } while((n=msgrcv(mid,&mesg,MAX,6,IPC_NOWAIT))>0) write(1,mesg.mtext,n); count ; if((n= = -1)&(count= =0)) printf(“\n No Message Queue on Queue:%d”,mid); }
Output:
Student@ubuntu:~$ gcc msgq.c
Student@ubuntu:~$ cat > fact
Hello
Hai
Welcome
^z
Student@ubuntu:~$ ./msgq.out
Queue id :0
Mesgq created
Hello
Hai
welcome
-
UpdatedOct 23, 2014
-
Views13,360
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.