Linux - Study Mode

[#846] 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")

ret = msgsnd(m_id,&data1,11,0)

printf("%d
",ret)

if(msgrcv(m_id,&data2,11,1,0) == -1)
perror("msgrcv")

if(msgctl(m_id,IPC_RMID,0) != 0)
perror("msgctl")

return 0

}
Correct Answer

(A) 0

[#847] What is the output of this program? #include<stdio.h>
#include<pthread.h>

void *fun_t(void *arg)

void *fun_t(void *arg)
{
sleep(1)

}
int main()
{
pthread_t pt

void *res_t

if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror("pthread_create")

if(pthread_join(pt,&res_t) != 0)
perror("pthread_join")

printf("%s
",res_t)

return 0

}
Correct Answer

(B) segmentation fault

[#848] What is the output of this program? #include<stdio.h>
#include<fcntl.h>

int main()
{
int fd, count

char ch[10]

fd = open("example.txt",O_RDWR|O_CREAT)

write(fd,"linux",5)

lseek(fd,2,SEEK_END)

write(fd,"man",3)

lseek(fd,0,0)

count = read(fd,ch,10)

printf("%s
",ch)

return 0

}
Correct Answer

(A) linux

[#849] What is the output of this program? #include<stdio.h>

int main()
{
int fd[3],count

if (pipe(fd) != 0)
perror("pipe")

count = write(fd[2],"Hello",6)

printf("%d
",count)

return 0

}
Correct Answer

(C) -1

[#850] What is the output of this program? #include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
char *ptr

memcpy(ptr,"example",11)

printf("%s
",ptr)

return 0

}
Correct Answer

(B) segmentation fault