forked from hutianyi003/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.c
84 lines (72 loc) · 1.87 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#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("processInfo", O_CREATE );
close(fd);
fd = open("processInfo", O_WRONLY);
if(fd >= 0)
{
printf(1, "ok: open file succeed\n");
}
else
{
printf(1, "error: open file failed\n");
exit();
}
char str[] = "1 test 1\n2 blabla 2\n";
if(write(fd, str, sizeof(str)) != sizeof(str))
printf(1,"err");
else
printf(1,str);
close(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 = readline(fd, line, 100);
if(size > 100 || size < 0)
break;
char res[20];
char slash[] = " ";
int pos = 0;
//printf(1,"%d",id);//输出编号
//printf(1,slash);
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,"ERR STATE\n"); break;
}
id++;
}
//printf(1, "read all\n");
close(fd);
return exit();
}