27 #include <sys/types.h>
29 #include <utils/ipc/semset.h>
43 signal_handler(
int signum)
45 cout <<
"Signal handler called" << endl;
50 main(
int argc,
char **argv)
53 signal(SIGINT, signal_handler);
57 if ((child_pid = fork()) == 0) {
62 while (!s2->
valid()) {
69 cout <<
"Child: Unlocking child lock" << endl;
72 cout <<
"Child: Waiting for father lock to become ready" << endl;
73 s2->
lock(FATHER_LOCK);
74 cout <<
"Child: Father lock aquired, unlocking" << endl;
77 cout <<
"Child: Sleeping" << endl;
79 cout <<
"Child: Locking child lock" << endl;
81 cout <<
"Child: Sleeping again" << endl;
85 cout <<
"Child: Destroying s2" << endl;
96 cout <<
"Father: Unlocking father lock" << endl;
99 cout <<
"Father: Waiting for child lock to become ready" << endl;
100 s1->
lock(CHILD_LOCK);
101 cout <<
"Father: Child lock aquired, unlocking" << endl;
104 cout <<
"Father: Sleeping" << endl;
106 cout <<
"Father: Locking father lock" << endl;
107 s1->
lock(FATHER_LOCK);
108 cout <<
"Father: again" << endl;
112 cout <<
"Father: Waiting for child to exit" << endl;
114 waitpid(child_pid, &status, 0);
116 cout <<
"Father: Destroying s1" << endl;