KEMBAR78
Lab3-Shared Memory | PDF | Computer File | Programming
0% found this document useful (0 votes)
89 views4 pages

Lab3-Shared Memory

Uploaded by

asiaB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views4 pages

Lab3-Shared Memory

Uploaded by

asiaB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Page 1 of 4

HTU Course Title: Operating System


HTU Course Code:
Session --: Practical Session on Shared Memory
Exam time: 150 minutes
Date: --/11/2024
Student name:
Student ID:

Lab Objectives:

➢ Be familiar with the concept of Process communication.


➢ Learn the implementation of shared memory.

Instructions:

➢ Do not use AI to solve tasks.

Getting started with gcc compiler

gcc is a Unix-based C compiler usually operated via the command line. The main actions in gcc compiler are
as following:

1. Invoking a source code.

You can invoke gcc on a source code file simply by typing:

gcc filename

2. Creating executable file for the output.

You can create an output file for executing the source code by typing:

-o outputfile

Note that the output file will be automatically saved in the working directory.

3. Running the program.


You can run your program by typing

./outputfile

The ./ is there to ensure you run the program for the current working directory.

1
Page 2 of 4

Pre Lab-Questions:

Task1: Complete the pointer code by following the TODO comments, you will find it in the
Pointer.c file.

Task2: Complete the Process code by following the TODO comments, you will find it in the Process.c
file.

In Lab-Questions:

Task1: Write a C programs for inter-process communication (IPC) using shared memory, that
performs the following scenario:

• Sender (sender.c): Prompt the user for a string and an integer, and store them in shared memory.

• Receiver (receiver.c): Check if the integer is even or odd and print the string along with this
result.

o Sample output:

Task2: Write a program where:

1. The child process generates 100 random numbers and writes them to shared memory.
2. The parent process reads numbers from shared memory and calculates the cumulative sum.
3. The program terminates when all numbers are processed, and the parent displays the total
sum.

2
Page 3 of 4

o Sample output:

Task3 : Write a program where:

1. Use shared memory to store an array of numbers.


2. The parent process writes 10 numbers into the shared memory.
3. Fork 3 child processes, where:
o Child 1 computes the factorial of the first 3 numbers.
o Child 2 computes the factorial of the next 3 numbers.
o Child 3 computes the factorial of the last 4 numbers.
4. Store the results back in shared memory and let the parent print them.
5. Draw picture of the hierarchical process tree after write the program,and display the relation
with shared memeory.

o Sample output:

3
Page 4 of 4

You might also like