1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include "rc.h"
#include <signal.h>
#include <termios.h>
// -----------------------------------------------------------------------
// exports
Thread *
getjob(int pid, int *index)
{
int i;
Thread *job;
for(i=0,job=shell.jobs; job && job->pid != pid; i++, job=job->next)
;
return job;
}
void
report(Thread *job, int index)
{
switch(job->wait.status){
case PDone:
print(shell.err, "job %d [%d]: done\n", index, job->pid);
break;
case PStop:
print(shell.err, "job %d [%d]: suspended\n", index, job->pid);
break;
case PAgain:
print(shell.err, "job %d [%d]: continued\n", index, job->pid);
break;
case PRun:
print(shell.err, "job %d [%d]: running\n", index, job->pid);
break;
default:
fatal("bad wait status: %d\n", job->wait.status);
}
}
void
wakeup(Thread *t)
{
int i;
t->wait.status = PRun;
for(i=0; i < t->wait.len; i++){
if(t->wait.on[i].status == PStop)
t->wait.on[i].status = PRun;
}
}
void
foreground(Thread *job, int signal)
{
tcsetpgrp(0, job->pgid);
if(signal){
if(kill(-job->pgid, SIGCONT) < 0)
perror("kill[SIGCONT]");
}
waitall(job);
tcsetpgrp(0, shell.pid);
}
void
addjob(Thread *job)
{
job->next = shell.jobs;
shell.jobs = job;
}
void
deljob(Thread *job)
{
Thread **jp;
for(jp = &shell.jobs; *jp && *jp != job; jp = &(*jp)->next)
;
*jp = job->next;
}
|