Lab Assignment--Shell Scripts


Your task is to create a shell script that is able to remove all of the semaphores that you have created.

Required Tools:

Recommended Steps

  1. compile program7_1.cpp
  2. run it a couple of times to create some semaphores
  3. try ipcs -s
  4. now try and print only the semaphores associated with you (try grep)
  5. you only want to print the second set of numbers (you can do that with awk)
  6. build a for loop that uses a list of semaphore id's (obtained through ipcs, grep, and awk)
  7. In the loop, print the semaphore id and remove the semaphore

Sample run:

% ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x00000174 458752     nova      666        3
0x00000000 491521     nova      600        3
0x00000000 524290     nova      600        3
0x00000000 557059     nova      600        3
0x00000000 589828     nova      600        3

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

% exercise.sh
Removing semaphore with ID number 458752
Removing semaphore with ID number 491521
Removing semaphore with ID number 524290
Removing semaphore with ID number 557059
Removing semaphore with ID number 589828

% ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

Deliverables: