Linux - Study Mode
[#891] 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(msgrcv(m_id,&data2,11,0) == -1)
perror("msgrcv")
printf("%s
",data2.buff)
if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl")
return 0
}
Correct Answer
(B) this program will give an error
[#892] What is the output of this progarm? #include<stdio.h>
#include<unistd.h>
int main()
{
execl("/bin/ls","ls",NULL)
return 0
}
Correct Answer
(C) the program will execute just like "ls" command
[#893] In which condition this program will print the string "Example"? #include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr
ptr = (int *)malloc(sizeof(int)*10)
if (ptr == NULL)
printf("Example
")
return 0
}
Correct Answer
(A) if the memory could not be allocated to the pointer "ptr"
[#894] What will print as the SIGINT signal hits the running process of this program? #include<stdio.h>
#include<stdlib.h>
#include<signal.h>
void response (int)
void response (int sig_no)
{
printf("%s",sys_siglist[sig_no])
}
int main()
{
signal(SIGINT,response)
while(1){
printf("Example
")
sleep(1)
}
return 0
}
Correct Answer
(A) Interrupt
[#895] What is the output of this program? #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *ptr
ptr = (char*)malloc(sizeof(char)*8)
strcpy(ptr,"example")
printf("%d
",*ptr)
return 0
}
Correct Answer
(C) 101