1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 |
|
---|
4 | #include <llapi.h>
|
---|
5 | #include <unistd.h>
|
---|
6 | #include <fcntl.h>
|
---|
7 | #include <time.h>
|
---|
8 | #include <string.h>
|
---|
9 | #include <errno.h>
|
---|
10 |
|
---|
11 | #include <sys/types.h>
|
---|
12 | #include <sys/stat.h>
|
---|
13 |
|
---|
14 | #define CHAR_BUFFER 256
|
---|
15 | #define FILE_LENGTH 1024
|
---|
16 |
|
---|
17 | int createCmd(char *prog, char *params, char *addr, size_t adrrLength)
|
---|
18 | {
|
---|
19 |
|
---|
20 | FILE * fd;
|
---|
21 | fd = fopen(addr,"wx");
|
---|
22 | if(fd!=NULL)
|
---|
23 | {
|
---|
24 | fprintf(fd,"# File created by LoadLeveler DRMAA. If no LL DRMAA aplications are running you can delete this file\n");
|
---|
25 | fprintf(fd,"# @ initialdir = %s\n","/home/mamon/michal/5_1_wait");
|
---|
26 | fprintf(fd,"# @ executable = %s\n",prog);
|
---|
27 | fprintf(fd,"# @ arguments = %s\n",params);
|
---|
28 | fprintf(fd,"# @ output = %s.out\n",prog);
|
---|
29 | fprintf(fd,"# @ error = %s.err\n",prog);
|
---|
30 | fprintf(fd,"# @ queue\n");
|
---|
31 | fclose(fd);
|
---|
32 | }
|
---|
33 | else
|
---|
34 | {
|
---|
35 | perror("Can't create cmd file\n"); //przetestowac
|
---|
36 | exit(1);
|
---|
37 | }
|
---|
38 | return 0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | int compare(char *ad1,char *ad2,size_t l1,size_t l2)
|
---|
42 | {
|
---|
43 | int i = 0;
|
---|
44 | size_t min = l2;
|
---|
45 | char * inx = ad2;
|
---|
46 | if(l1<l2)
|
---|
47 | {
|
---|
48 | min = l1;
|
---|
49 | inx = ad1;
|
---|
50 | }
|
---|
51 |
|
---|
52 | for(i = 0;i<min;i++)
|
---|
53 | if(ad1[i]!=ad2[i]) return 0;
|
---|
54 |
|
---|
55 | return 1;
|
---|
56 | }
|
---|
57 |
|
---|
58 | int endState(char *buffer,size_t length)
|
---|
59 | {
|
---|
60 | if(compare(buffer,"JOB_COMPLETED",length,sizeof("JOB_COMPLETED")) ||
|
---|
61 | compare(buffer,"JOB_REJECTED",length,sizeof("JOB_REJECTED")) ||
|
---|
62 | compare(buffer,"JOB_REMOVED",length,sizeof("JOB_REMOVED")) ||
|
---|
63 | compare(buffer,"JOB_NOTRUN",length,sizeof("JOB_NOTRUN")) ||
|
---|
64 | compare(buffer,"JOB_VACATED",length,sizeof("JOB_VACATED")) )
|
---|
65 | return 1;
|
---|
66 | else
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 |
|
---|
70 | int fgetline(char str[], int maxlen, FILE *fp)
|
---|
71 | {
|
---|
72 | int last;
|
---|
73 | if(!fgets(str, maxlen, fp))
|
---|
74 | return -1;
|
---|
75 | last = strlen(str)-1;
|
---|
76 | if(str[last]=='\n') str[last] = '\0';
|
---|
77 | return 0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | int main(int argc, char *argv[])
|
---|
81 | {
|
---|
82 | LL_job test;
|
---|
83 | int status;
|
---|
84 | char *mon = "/home/mamon/michal/5_1_wait/mon";
|
---|
85 | FILE * fd;
|
---|
86 | char *prog;
|
---|
87 | char *fifoAddr;
|
---|
88 | char templateCmd[] = "/tmp/drmaa_cmd_XXXXXX";
|
---|
89 | char templateFifo[] = "/tmp/drmaa_fifo_XXXXXX";
|
---|
90 |
|
---|
91 | if (argc<2)
|
---|
92 | {
|
---|
93 | fprintf(stderr, "usage: example <path-to-job> [args]\n");
|
---|
94 | return 1;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | prog=mktemp(templateCmd);
|
---|
99 |
|
---|
100 | if(argc==3)
|
---|
101 | createCmd(argv[1],argv[2],prog,CHAR_BUFFER);
|
---|
102 | else
|
---|
103 | createCmd(argv[1],"",prog,CHAR_BUFFER);
|
---|
104 |
|
---|
105 | fifoAddr=mktemp(templateFifo);
|
---|
106 |
|
---|
107 | status = llsubmit(prog,mon,fifoAddr,&test,LL_JOB_VERSION);
|
---|
108 |
|
---|
109 | remove(prog);
|
---|
110 | llfree_job_info(&test,LL_JOB_VERSION);
|
---|
111 |
|
---|
112 | if(status==0)
|
---|
113 | {
|
---|
114 | char buffer[CHAR_BUFFER];
|
---|
115 | int idGot=1;
|
---|
116 | //int i = 3;
|
---|
117 |
|
---|
118 | mkfifo(fifoAddr,0600);
|
---|
119 | fd=fopen(fifoAddr,"r"); //x
|
---|
120 |
|
---|
121 | do
|
---|
122 | {
|
---|
123 | if(fgetline(buffer,sizeof(buffer),fd)!=-1)
|
---|
124 | {
|
---|
125 | if(idGot==1)
|
---|
126 | {
|
---|
127 | idGot=0;
|
---|
128 | printf("Your job has been submitted with id %s\n",buffer);
|
---|
129 | }
|
---|
130 | }
|
---|
131 | //printf("a: %s\n",buffer);
|
---|
132 | } while(!endState(buffer,sizeof(buffer)));
|
---|
133 | printf("End state: %s\n",buffer);
|
---|
134 | fgetline(buffer,sizeof(buffer),fd);
|
---|
135 | printf("Exit status: %s\n",buffer);
|
---|
136 |
|
---|
137 | fclose(fd);
|
---|
138 |
|
---|
139 | unlink(fifoAddr);
|
---|
140 | }
|
---|
141 | else
|
---|
142 | printf("error\n");
|
---|
143 |
|
---|
144 | return 0;
|
---|
145 | }
|
---|