1 | /* |
---|
2 | * get_status.c |
---|
3 | * |
---|
4 | * Created on: 2 juil. 2015 |
---|
5 | * Author: cresson |
---|
6 | */ |
---|
7 | #include "drmaa.h" |
---|
8 | #include <stdlib.h> /* exit, EXIT_FAILURE */ |
---|
9 | |
---|
10 | int main (int argc, char **argv) { |
---|
11 | if (argc<2) |
---|
12 | { |
---|
13 | printf ("One argument is missing (Job ID)\n"); |
---|
14 | return EXIT_FAILURE; |
---|
15 | } |
---|
16 | |
---|
17 | const char * jobid = argv[1]; |
---|
18 | char error[DRMAA_ERROR_STRING_BUFFER]; |
---|
19 | int errnum = 0; |
---|
20 | int status = 0; |
---|
21 | |
---|
22 | errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); |
---|
23 | |
---|
24 | if (errnum != DRMAA_ERRNO_SUCCESS) { |
---|
25 | fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); |
---|
26 | return EXIT_FAILURE; |
---|
27 | } |
---|
28 | |
---|
29 | errnum = drmaa_job_ps (jobid, &status, error, |
---|
30 | DRMAA_ERROR_STRING_BUFFER); |
---|
31 | |
---|
32 | if (errnum != DRMAA_ERRNO_SUCCESS) { |
---|
33 | fprintf (stderr, "Could not get job' status: %s\n", error); |
---|
34 | return EXIT_FAILURE; |
---|
35 | } |
---|
36 | else { |
---|
37 | switch (status) { |
---|
38 | case DRMAA_PS_UNDETERMINED: |
---|
39 | printf ("Job status cannot be determined\n"); |
---|
40 | break; |
---|
41 | case DRMAA_PS_QUEUED_ACTIVE: |
---|
42 | printf ("Job is queued and active\n"); |
---|
43 | break; |
---|
44 | case DRMAA_PS_SYSTEM_ON_HOLD: |
---|
45 | printf ("Job is queued and in system hold\n"); |
---|
46 | break; |
---|
47 | case DRMAA_PS_USER_ON_HOLD: |
---|
48 | printf ("Job is queued and in user hold\n"); |
---|
49 | break; |
---|
50 | case DRMAA_PS_USER_SYSTEM_ON_HOLD: |
---|
51 | printf ("Job is queued and in user and system hold\n"); |
---|
52 | break; |
---|
53 | case DRMAA_PS_RUNNING: |
---|
54 | printf ("Job is running\n"); |
---|
55 | break; |
---|
56 | case DRMAA_PS_SYSTEM_SUSPENDED: |
---|
57 | printf ("Job is system suspended\n"); |
---|
58 | break; |
---|
59 | case DRMAA_PS_USER_SUSPENDED: |
---|
60 | printf ("Job is user suspended\n"); |
---|
61 | break; |
---|
62 | case DRMAA_PS_USER_SYSTEM_SUSPENDED: |
---|
63 | printf ("Job is user and system suspended\n"); |
---|
64 | break; |
---|
65 | case DRMAA_PS_DONE: |
---|
66 | printf ("Job finished normally\n"); |
---|
67 | break; |
---|
68 | case DRMAA_PS_FAILED: |
---|
69 | printf ("Job finished, but failed\n"); |
---|
70 | break; |
---|
71 | } /* switch */ |
---|
72 | } /* else */ |
---|
73 | |
---|
74 | |
---|
75 | errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); |
---|
76 | |
---|
77 | if (errnum != DRMAA_ERRNO_SUCCESS) { |
---|
78 | fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); |
---|
79 | return EXIT_FAILURE; |
---|
80 | } |
---|
81 | |
---|
82 | return EXIT_SUCCESS; |
---|
83 | } |
---|
84 | |
---|