forked from SpongebBob/HomeworkSchedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enq.c
executable file
·88 lines (76 loc) · 1.59 KB
/
enq.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
85
86
87
88
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <fcntl.h>
#include "job.h"
#define DEBUG
/*
* ÃüÁîÓï·¨¸ñʽ
* enq [-p num] e_file args
*/
void usage()
{
printf("Usage: enq[-p num] e_file args\n"
"\t-p num\t\t specify the job priority\n"
"\te_file\t\t the absolute path of the exefile\n"
"\targs\t\t the args passed to the e_file\n");
}
int main(int argc,char *argv[])
{
int p=0;
int fd;
char c,*offset;
struct jobcmd enqcmd;
if(argc==1)
{
usage();
return 1;
}
while(--argc>0 && (*++argv)[0]=='-')
{
while(c=*++argv[0])
switch(c)
{
case 'p':p=atoi(*(++argv));
argc--;
break;
default:
printf("Illegal option %c\n",c);
return 1;
}
}
if(p<0||p>3)
{
printf("invalid priority:must between 0 and 3\n");
return 1;
}
enqcmd.type=ENQ;
enqcmd.defpri=p;
enqcmd.owner=getuid();
enqcmd.argnum=argc;
offset=enqcmd.data;
while (argc-->0)
{
strcpy(offset,*argv);
strcat(offset,":");
offset=offset+strlen(*argv)+1;
argv++;
}
#ifdef DEBUG
//---lp--debug task 4--
printf("enqcmd cmdtype\t%d (-1 means ENQ, -2 means DEQ, -3 means STAT)\n"
"enqcmd owner\t%d\n"
"enqcmd defpri\t%d\n"
"enqcmd data\t%s\n"
"enqcmd argnum\t%d\n",
enqcmd.type,enqcmd.owner,enqcmd.defpri,enqcmd.data,enqcmd.argnum);
#endif
if((fd=open("/tmp/server",O_WRONLY))<0)
error_sys("enq open fifo failed");
if(write(fd,&enqcmd,DATALEN)<0)
error_sys("enq write failed");
close(fd);
return 0;
}