Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
programs: master.c and slave.c
author: Morgan Elder
Date: February 25 2022
The makefile will compile two executables called master and slave.
To compile simply use:
> make
To remove the executable files and object files:
> make clean
To remove output generated from running either master or slave:
> make remove_stuff
The master file master is executed with the following command:
> master -t ss n
The t option specifies the time ss (in seconds) until the master program will timeout and terminate.
The default number of seconds is 100.
The n argument is required and specifies the number of processes that the parent process will fork.
Each child process executes the slave program.
When the master program ends, the parent process deallocates all shared memory.
If master ends via timeout or user-generated interrupt signal (CTRL+C), then the parent process also
terminates all running child processes.
The slave program is executed in the following way:
> slave xx nn
Here, xx represents the process number spefied by the master program and nn is the number picked by
the child process when entering the critical section.
Note: The shmctl generates the error:
"shmctl: Operation not permitted"
According to the documentation, this error indicates that the current process does not have permission
to modify the shared memory. However, the only process in master that executes this operation is the parent
process which is the same process that created the shared memory. The issue is not currently resolved.