$30
CECS-326: Operating Systems
PROJECT 4
SEMAPHORE CREATION
Name: ____________________________________
Last, First
ABSOLUTELY NO LATE PROJECTS WILL BE ACCEPTED
PROJECT DESCRIPTION:
Write a program using C/C++ to do the following.
Create NS semaphores in a semaphore set. The values of the semaphores are provided via the command
line arguments. Provide error checking to make sure the number of semaphore values is matched to the
number of semaphores NS.
semctl ropt NS value1 value2 . . . valueNS
where:
ropt: option to remove the semaphores: r for remove, n for not remove.
NS: number of semaphores
value1, value2, . . ., valueNS: values of the semaphores in the semaphore set.
The program should display the semaphore identifier, time it is created, and the list of the semaphores with
their value. If not remove option is selected, the program should display error if the semaphores set has
already been created.
Examples of program output are shown below:
semctl r 5 5 3 4 11 2
Semaphore identifier 196608
Create Sun Nov 3 14:34:45 2002
Semaphore 0 has value of 5
Semaphore 1 has value of 3
Semaphore 2 has value of 4
Semaphore 3 has value of 11
Semaphore 4 has value of 2
semctl n 3 11 9
Arguments not matched. Number of semaphores is 3
semctl n 3 1 2 4
semget: File exists
DOCUMENTATION:
The project must be carefully documented. The write-up must include: one page of problem analysis and
discussion (include a flow chart or structure chart when relevant), program listing with proper comments,
one page of output listing using typical values of NS and values. The discussion should include general
considerations, UNIX function calls, any reasonable assumptions, and any other relevant information.
Attach this sheet as the front page of your project. Firmly staple the entire project together. No folder is
used.
END OF PROJECT 4