1 /*********************** wait.c file ***********************************/
3 int grave() /* this grave() does NOT free the ZOMBIE proc */
5 printf("\n*************************************\n");
6 printf("Process %d %c %s", running
->pid
, 7,gasp
[running
->pid
% 4]);
7 printf("\n*************************************\n");
12 int wait(exitValue
) int *exitValue
;
19 for (i
=0; i
<NPROC
; i
++){
21 if (p
->ppid
== running
->pid
&& p
->status
!= FREE
){
23 /* lay the dead child to rest */
24 if (p
->status
== ZOMBIE
){
25 *exitValue
= p
->exitValue
;
26 p
->status
= FREE
; /* free its PROC */
29 return(p
->pid
); /* return its pid */
33 if (!found
) /* no child */
35 sleep(running
); /* has kids still alive */
39 int enterSleep(p
) PROC
*p
;
53 int sleep(event
) int event
;
55 printf("\n*************************************\n");
56 printf("Proc %d going to sleep on event=%x", running
->pid
, event
);
57 printf("\n*************************************\n");
58 running
->status
= SLEEP
;
59 running
->event
= event
;
60 // enter sleepList FIFO
66 /* wake up ALL tasks sleeping on event */
67 int wakeup(event
) int event
;
74 if (p
->event
!= event
){
85 enqueue(&readyQueue
, p
);
86 printf("wakeup proc %d\n", p
->pid
);
90 // not the first element
91 q
->next
= p
->next
; // delete p from list
94 enqueue(&readyQueue
, p
);
95 printf("wakeup proc %d\n", p
->pid
);
101 // YOU WRITE C CODE TO DO THESE
103 int do_exit(v
) int v
;
106 printf("proc %d in kexit(): exitValue=%d\n", running
->pid
, v
);
108 (1). if caller is P1
&& there are other procs still existing
, do NOT die
;
110 (2). Send
children (dead
or alive
) to P1
;
111 Wakeup P1
if any child is a ZOMBIE
;
113 (3). Record exitValue
and become a ZOMBIE
;
117 (5). call
grave() to
tswitch();
121 int do_wait(uptr
) int *uptr
; // 0 for Kmode, nonzero for umode
123 wait
for a ZOMBIE child
:
124 write ZOMBIE
's exitValue to U space;
125 return ZOMBIE's pid to U space
;