Linux - Study Mode
[#841] What is the output of this program? #include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main()
{
int fd
char *buff
buff = (char *)malloc(sizeof(char)*5)
fd = open("example.txt",O_RDWR|O_CREAT)
write(fd,"Linux",5)
read(fd,buff,5)
printf("%s
",buff)
}
Correct Answer
(A) it will print nothing
[#842] What is the output of this program? #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int ptr
ptr = (int)malloc(sizeof(int)*10)
return 0
}
Correct Answer
(D) none of the mentioned
[#843] What is the output of this program? #include<stdio.h>
#include<fcntl.h>
int main()
{
int fd, fd2, ret
fd = open("hello.c",O_RDONLY)
ret = close(fd2)
printf("%d
",ret)
}
Correct Answer
(C) -1
[#844] What is the output of this program? #include<stdio.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<semaphore.h>
int main()
{
sem_t* sem_id
sem_id = sem_open("sem_value",O_CREAT,0666,0)
if(sem_id == SEM_FAILED)
perror("sem_open")
sem_post(sem_id)
printf("Example
")
if(sem_close(sem_id) == -1)
perror("sem_close")
return 0
}
Correct Answer
(B) this program will print the string "Example"
[#845] What is the output of this program? #include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
void *fun_t(void *arg)
void *fun_t(void *arg)
{
sem_post(&st)
pthread_exit("Bye")
}
int main()
{
pthread_t pt
sem_t st
void *res_t
if(pthread_create(&pt,NULL,fun_t,NULL) == -1)
perror("pthread_create")
if(sem_init(&st,0,0) != 0)
perror("sem_init")
if(sem_wait(&st) != 0)
perror("sem_wait")
printf("Example
")
if(pthread_join(pt,&res_t) == -1)
perror("pthread_join")
if(sem_destroy(&st) != 0)
perror("sem_destroy")
return 0
}
Correct Answer
(B) this program will give an error