-
#include
-
#include
-
#include<sys/stat.h>
-
#include
-
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_wait(sem_id);
-
printf("n");
-
if(sem_close(sem_id) == -1)
-
perror("sem_close");
-
return 0;
-
}
a) this program will print the string “”
b) this process will block
c) segmentaion fault
d) none of the mentioned
2. What is the output of this program?
-
#include
-
#include
-
#include<sys/stat.h>
-
#include
-
int main()
-
{
-
sem_t* sem_id;
-
int value;
-
sem_id = sem_open("sem_value",O_CREAT,0666,0);
-
if(sem_id == SEM_FAILED)
-
perror("sem_open");
-
if(sem_getvalue(sem_id,&value) == -1)
-
perror("sem_getvalue");
-
printf("%dn",value);
-
sem_wait(sem_id);
-
printf("n");
-
if(sem_close(sem_id) == -1)
-
perror("sem_close");
-
return 0;
-
}
a) 0
b)
c) Both 0 and
d) None of the mentioned
3. What is the output of this program?
-
#include
-
#include
-
#include<sys/stat.h>
-
#include
-
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("n");
-
if(sem_close(sem_id) == -1)
-
perror("sem_close");
-
return 0;
-
}
a) this process will block
b) this program will print the string “”
c) segmentation fault
d) none of the mentioned
4. What is the output of this program?
-
#include
-
#include
-
#include<sys/stat.h>
-
#include
-
int main()
-
{
-
sem_t* sem_id;
-
sem_id = sem_open("sem_value",O_CREAT,0666,0);
-
if(sem_id == SEM_FAILED)
-
perror("sem_open");
-
if(sem_close(sem_id) == -1)
-
perror("sem_close");
-
sem_wait(sem_id);
-
printf("n");
-
return 0;
-
}
a) this process will block
b) this program will print the string “”
c) segmentation fault
d) none of the mentioned
5. What is the output of this program?
-
#include
-
#include
-
#include<sys/stat.h>
-
#include
-
int main()
-
{
-
sem_t* sem_id;
-
int value;
-
sem_id = sem_open("new_13",O_CREAT,0666,3);
-
if(sem_id == SEM_FAILED)
-
perror("sem_open");
-
sem_wait(sem_id);
-
sem_wait(sem_id);
-
sem_wait(sem_id);
-
sem_wait(sem_id);
-
sem_post(sem_id);
-
sem_post(sem_id);
-
sem_getvalue(sem_id,&value);
-
printf("%dn",value);
-
if(sem_close(sem_id) == -1)
-
perror("sem_close");
-
return 0;
-
}
a) 2
b) 3
c) 0
d) none of the mentioned
6. What is the output of this program?
-
#include
-
#include
-
#include<sys/stat.h>
-
#include<sys/mman.h>
-
int main()
-
{
-
int s_id;
-
s_id = shm_open("shared_mem",O_CREAT|O_RDWR,0666);
-
printf("%dn",s_id);
-
if(shm_unlink("shared_mem") == -1)
-
perror("shm_unlink");
-
return 0;
-
}
a) -1
b) 1
c) 2
d) 3
7. What is the output of this program?
-
#include
-
#include
-
#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;
-
}
a) mmap: Success
b) mmap: Failure
c) munmap: Success
d) munmap: Failure
8. What is the output of this program?
-
#include
-
#include
-
#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");
-
ptr = mmap(ptr,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;
-
}
a) mmap: Success
mmap: Success
b) mmap: Success
mmap: Failure
c) segmentation fault
d) none of the mentioned
9. What is the output of this program?
-
#include
-
#include
-
#include
-
#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 grantedn");
-
return 0;
-
}
a) Permission granted
: Success
b) Permission granted
c) segmentation fault
d) none of the mentioned
10. What is the output of this program?
-
#include
-
#include
-
#include
-
#include<sys/stat.h>
-
#include<sys/mman.h>
-
int main()
-
{
-
int s_id;
-
s_id = shm_open("shared_memory",O_TRUNC,0666);
-
if(s_id == -1)
-
perror("shm_openn");
-
return 0;
-
}
a) this program will give an error because OTRUNC is not a valid flag
b) this program will give an error
c) this program will give segmentation fault
d) none of the mentioned