1. Linux filesystem contains mainly
2. Race condition can be avoided by using
3. Shell is ?
4. Which system call is used to create Sys V message Queue.
5. Binary or executable files are:
6. Which variable contains current shell process id
7. Proc filesystem does not contains
8. 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,ret;
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");
ret = msgrcv(m_id,&data2,11,1,0);
printf("%d\n",ret);
if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl");
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,ret;
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");
ret = msgrcv(m_id,&data2,11,1,0);
printf("%d\n",ret);
if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl");
return 0;
}
9. What is output of the following program?
int main()
{
fork();
fork();
fork();
if (wait(0) == -1)
printf("leaf child\n");
}
int main()
{
fork();
fork();
fork();
if (wait(0) == -1)
printf("leaf child\n");
}
10. On which system call, this program (process) waits until the server responds?
#include<stdio.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror("fd_sock");
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr("127.0.0.1");
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
if(fd == -1)
perror("connect");
write(fd,"Hello\n",6);
return 0;
}
#include<stdio.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror("fd_sock");
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr("127.0.0.1");
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
if(fd == -1)
perror("connect");
write(fd,"Hello\n",6);
return 0;
}
Read More Section(Linux)
Each Section contains maximum 100 MCQs question on Linux. To get more questions visit other sections.