Linux - Study Mode
[#866] What is the output of this pogram? #include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/sem.h>
static int sem_p(void)
static int sem_v(void)
union semun{
int val
struct semid_ds *buf
unsigned short array
}
int sem_id
struct semid_ds myds
struct sembuf mybuf
union semun myun
static int sem_p(void)
{
mybuf.sem_num = 0
mybuf.sem_op = -1
mybuf.sem_flg = SEM_UNDO
semop(sem_id,&mybuf,1)
}
static int sem_v(void)
{
mybuf.sem_num = 0
mybuf.sem_op = 1
mybuf.sem_flg = SEM_UNDO
semop(sem_id,&mybuf,1)
}
int main()
{
int wfd, rfd
sem_id = semget((key_t)911,1,0666 | IPC_CREAT)
myun.val = 0
semctl(sem_id,0,SETVAL,myun)
sem_p()
printf("Example
")
sem_v()
semctl(sem_id,0,IPC_RMID,myun)
return 0
}
Correct Answer
(B) this process will remain block
[#867] What is the output of this program? #include<stdio.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/mman.h>
int main()
{
int s_id
int *ptr
s_id = shm_open("shared_mem",O_CREAT|O_RDWR,0666)
if(s_id == -1)
perror("shm_open")
ptr = mmap(NULL,100,PROT_WRITE,MAP_PRIVATE,s_id,0)
if(ptr == MAP_FAILED)
perror("mmap")
if(munmap(ptr,100) == -1)
perror("munmap")
if(shm_unlink("shared_mem") == -1)
perror("shm_unlink")
return 0
}
Correct Answer
(A) mmap: Success
[#868] This program can send the request to #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("193.39.0.4")
len = sizeof(add_server)
fd = connect(fd_client,(struct sockaddr*)&add_server,len)
if(fd == -1)
perror("connect")
return 0
}
Correct Answer
(A) the system having IP address 193.39.0.4
[#869] What will happen if we press "Ctrl+c" key two times after running this program? #include<stdio.h>
#include<signal.h>
void response(int)
void response(int sig_no)
{
printf("Linux
")
signal(SIGINT,SIG_DFL)
}
int main()
{
signal(SIGINT,response)
while(1){
printf("Example
")
sleep(1)
}
return 0
}
Correct Answer
(B) process will terminate in the second time
[#870] What is the output of this program? #include<stdio.h>
#include<fcntl.h>
int main()
{
pid_t fd
char ch
int count
fd = open("demo.c",O_RDONLY)
do{
count = read(fd,&ch,1)
printf("%c",ch)
}while(count)
return 0
}
Correct Answer
(B) it will print the source code of the source file "demo.c"