Question: Task 1: Create and destroy a shared memory segment Place your code for this task in a directory named task1. Write a C program in

Task 1: Create and destroy a shared memory segment

Place your code for this task in a directory named task1.

Write a C program in a file named producer.c that:

1. Creates a shared memory segment ofsize 32 bytes.

2. Sleeps for 10 seconds using the sleep function.

3. Destroys the shared memory segment.

4. Exits, returning an appropriate status code.

You will need to research the Linux system calls necessary to accomplish this. At each of the steps listed above, print the status of your program to stdout (standard out) using printf. For example:

$ ./producer

-Using key 17102569

-Shared memory segment created with ID 2097152

-Sleeping for 10 seconds!!.

-Shared memory segment destroyed

While developing your solution, make use of the ipcs command to list all shared memory segments on the system (i.e., the VM). Until you get segment removal working, the ipcrm command can be used for cleanup; the -m option will remove a shared memory segment with a specific ID. Consult the relevant man pages or links for further information on these commands.

$ ipcs

------ Shared Memory Segments --------

key shmid owner perms bytes nattch

.... 98304 ..... ..... 32 ........

$ ipcrm -m 98304 #Removes the segment with id 98304

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!