forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 12
/
jobs.c
59 lines (51 loc) · 1.36 KB
/
jobs.c
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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "jobsconst.h"
enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
int main(void)
{
int fd;
fd = open(JOBS_FILENAME, O_RDONLY);
if(fd >= 0)
{
//printf(1, "ok: open file succeed\n");
}
else
{
printf(1, "error: open file failed\n");
exit();
}
char* line = " ";
int id = 1;
int size;
while(1)//读入每行
{
size = jobs_readline(fd, line, 100);
if(size > 100 || size < 0)
break;
char res[20];
char slash[] = " ";
int pos = 0;
pos = partition(line, res, pos);
int pid = atoi(res);
int state = getstate(pid);
pos = partition(line, res, pos);
printf(1, res);//输出名称
printf(1,slash);
switch(state)
{
case UNUSED: printf(1,"UNUSED\n"); break;
case EMBRYO: printf(1,"EMBRYO\n"); break;
case SLEEPING: printf(1,"SLEEPING\n"); break;
case RUNNABLE: printf(1,"RUNNABLE\n"); break;
case ZOMBIE: printf(1,"ZOMBIE\n"); break;
default: printf(1,"STOPPED\n"); break;
}
id++;
}
//printf(1, "read all\n");
close(fd);
return exit();
}