Starting from:

$30

CECS326- Homework 10 Solved

Purpose: A PROGRAMMING assignment to gain experience with signals and semaphors.

You will build an intersection control system.

Create and initialize a semaphore before you fork. Print the semaphor ID.

After the fork, the child handles traffic in the N/S direction; the parent handles traffic in the E/W direction. Both try to get their cars into the intersection as soon as possible.

Handling of the intersection must proceed as follows:

1)  get a lock on the intersection

2)  print ”N/S car entering intersection” (or E/W car if you’re the parent).

3)  Sleep 1 seconds, this time represents how long it takes to cross the intersection.

4)  print ”N/S car leaving intersection”

5)  release the lock on the intersection

Both the parent and the child should loop until they have gotten 10 cars across the intersection (i.e., loop 10 times).

Demo: Your traffic control program. The instructor will also want to look at the code.

Nathan Pickrell                        3 October 2019 (Week 6 Lecture 2)                        Due: 8 October 2019 (Week 7, Lab 1)

More products