Linux - Study Mode

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

void response (int)

void response (int sig_no)
{
printf("%s
",sys_siglist[sig_no])

printf("This is singal handler
")

}
int main()
{
pid_t child

int status

child = fork()

switch (child){
case -1 :
perror("fork")

exit (1)

case 0 :
kill(getppid(),SIGKILL)

printf("I am an orphan process because my parent has been killed by me
")

printf("Handler failed
")

break

default :
signal(SIGKILL,response)

wait(&status)

printf("The parent process is still alive
")

break

}
return 0

}
Correct Answer

(A) the child process kills the parent process

[#872] What is the output of second program if we run the demo1 first and after that we run demo2 in the different terminal? /*This is demo1.c*/
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<string.h>

int main()
{
int shm_id

char *addr

struct shmid_ds ds

shm_id = shmget((key_t)1234,10,0666|IPC_CREAT)

if(shm_id == -1){
perror("shmget")

}
addr = (char*)shmat(shm_id,NULL,SHM_RND)

if(addr == (char *)-1){
perror("shmat")

}
strcpy(addr,"Example")

if (shmdt(addr) != 0){
perror("shmdt")

}
if( shmctl(shm_id,IPC_RMID,0) == -1){
perror("shmctl")

}
return 0

}
/*This is demo2.c*/
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>

int main()
{
int shm_id

char *addr

struct shmid_ds ds

shm_id = shmget((key_t)1234,10,0666|IPC_CREAT)

if(shm_id == -1){
perror("shmget")

}
addr = (char*)shmat(shm_id,NULL,SHM_RND)

if(addr == (char *)-1){
perror("shmat")

}
printf("%s
",addr)

if (shmdt(addr) != 0){
perror("shmdt")

}
return 0

}
Correct Answer

(B) the program will nothing

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

int main()
{
int fd, count

char ch, *buff

buff = (char *)malloc(sizeof(char)*10)

fd = open("demo.c",O_RDONLY)

count = read(fd,buff,5)

printf("%d
",count)

return 0

}
Correct Answer

(A) 5

[#874] What is the output of this program? #include<stdio.h>
#include<fcntl.h>
#include<errno.h>
#include<sys/stat.h>
#include<sys/mman.h>

int main()
{
int s_id
s_id = shm_open("shared_mem",O_CREAT|O_RDWR,0666)
if(s_id != EACCES)
perror("Permission granted
")
return 0
}
Correct Answer

(A) Permission granted : Success

[#875] This program will print the #include<stdio.h>
#include<unistd.h>

int main()
{
long int value
value = sysconf(_SC_OPEN_MAX)
printf("%ld
",value)
return 0
}
Correct Answer

(A) maximum number of threads in current process