1.
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_wait(sem_id);
printf("Sanfoundry\n");
if(sem_close(sem_id) == -1)
perror("sem_close");
return 0;
}
2.
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;
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("%d\n",value);
sem_wait(sem_id);
printf("Sanfoundry\n");
if(sem_close(sem_id) == -1)
perror("sem_close");
return 0;
}
3.
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("Sanfoundry\n");
if(sem_close(sem_id) == -1)
perror("sem_close");
return 0;
}
4.
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");
if(sem_close(sem_id) == -1)
perror("sem_close");
sem_wait(sem_id);
printf("Sanfoundry\n");
return 0;
}
5.
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;
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("%d\n",value);
if(sem_close(sem_id) == -1)
perror("sem_close");
return 0;
}
6.
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;
s_id = shm_open("shared_mem",O_CREAT|O_RDWR,0666);
printf("%d\n",s_id);
if(shm_unlink("shared_mem") == -1)
perror("shm_unlink");
return 0;
}
7.
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;
}
8.
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");
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;
}
9.
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\n");
return 0;
}
10.
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_memory",O_TRUNC,0666);
if(s_id == -1)
perror("shm_open\n");
return 0;
}