What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
struct data_st{
long int id;
char buff[11];
};
int main()
{
int m_id;
struct data_st data1, data2;
m_id = msgget((key_t)181,0666|IPC_CREAT);
if(m_id == -1)
perror("msgget");
data1.id = 1;
strcpy(data1.buff,"Example");
if(msgsnd(m_id,&data1,11,0) == -1)
perror("msgsnd");
if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl");
if(msgrcv(m_id,&data2,11,1,0) == -1)
perror("msgrcv");
printf("%s\n",data2.buff);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
struct data_st{
long int id;
char buff[11];
};
int main()
{
int m_id;
struct data_st data1, data2;
m_id = msgget((key_t)181,0666|IPC_CREAT);
if(m_id == -1)
perror("msgget");
data1.id = 1;
strcpy(data1.buff,"Example");
if(msgsnd(m_id,&data1,11,0) == -1)
perror("msgsnd");
if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl");
if(msgrcv(m_id,&data2,11,1,0) == -1)
perror("msgrcv");
printf("%s\n",data2.buff);
return 0;
}
A. this program will print the string "Example"
B. this program will print the garbage value
C. this program will give segmentation fault
D. none of the mentioned
Answer: Option B
Related Questions on Linux
What command is used to count the total number of lines, words, and characters contained in a file?
A. countw
B. wcount
C. wc
D. count p
E. None of the above
What command is used with vi editor to delete a single character?
A. x
B. y
C. a
D. z
E. None of the above
Join The Discussion