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 | #include <sys/types.h>
|
---|
11 | #include <time.h>
|
---|
12 |
|
---|
13 | #include <sys/types.h>
|
---|
14 | #include <sys/ipc.h>
|
---|
15 | #include <sys/msg.h>
|
---|
16 |
|
---|
17 | #define CHAR_BUFFER 256
|
---|
18 | #define FILE_LENGTH 256
|
---|
19 |
|
---|
20 | void reverse(char s[])
|
---|
21 | {
|
---|
22 | int c,i,j;
|
---|
23 |
|
---|
24 | for(i=0,j=strlen(s)-1;i<j;i++,j--){
|
---|
25 | c=s[i];
|
---|
26 | s[i]=s[j];
|
---|
27 | s[j]=c;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | void itoa(int n,char s[])
|
---|
32 | {
|
---|
33 | int i, sign;
|
---|
34 |
|
---|
35 | if((sign = n) <0)
|
---|
36 | n=-n;
|
---|
37 | i=0;
|
---|
38 | do{
|
---|
39 | s[i++]=n%10+'0';
|
---|
40 | } while((n/=10)>0);
|
---|
41 | if(sign<0)
|
---|
42 | s[i++]='-';
|
---|
43 | s[i]='\0';
|
---|
44 | reverse(s);
|
---|
45 | }
|
---|
46 |
|
---|
47 | int main(int argc, char *argv[])
|
---|
48 | {
|
---|
49 | int fd = -1;
|
---|
50 | int fp;
|
---|
51 | char* file;
|
---|
52 | char buf[CHAR_BUFFER]="";
|
---|
53 | char adrr[256] = "/home/mamon/michal/5_1/test_mon.txt";
|
---|
54 | uid_t id;
|
---|
55 | time_t rawtime;
|
---|
56 | struct tm * timeinfo;
|
---|
57 |
|
---|
58 | time ( &rawtime );
|
---|
59 | timeinfo = localtime ( &rawtime );
|
---|
60 |
|
---|
61 | fd = open(adrr,O_WRONLY | O_CREAT | O_APPEND, 0644); // DRMAA powinna byc thread-safe, wiec nazwa pliku musi byc za kazdym razem inna
|
---|
62 | if(fd==-1)
|
---|
63 | exit(0);
|
---|
64 |
|
---|
65 | file = malloc(FILE_LENGTH);
|
---|
66 | memset(file,'\0',FILE_LENGTH);
|
---|
67 | strftime (file, 40, "[%x %X] \n",timeinfo);
|
---|
68 | write(fd,file,FILE_LENGTH);
|
---|
69 |
|
---|
70 | memset(file,'\0',FILE_LENGTH);
|
---|
71 | gethostname(buf,CHAR_BUFFER);
|
---|
72 | /*strcat(file,"Hostname: ");
|
---|
73 | strcat(file,buf);
|
---|
74 | strcat(file,"\n");*/
|
---|
75 | sprintf(file,"Hostname: %s\n",buf);
|
---|
76 | write(fd,file,FILE_LENGTH);
|
---|
77 |
|
---|
78 | memset(file,'\0',FILE_LENGTH);
|
---|
79 |
|
---|
80 | /*memset(buf,'\0',CHAR_BUFFER);
|
---|
81 | strcat(file,"UID: ");
|
---|
82 | id = getuid();
|
---|
83 | itoa(id,buf);
|
---|
84 | strcat(file,buf);
|
---|
85 | strcat(file,"\n");*/
|
---|
86 |
|
---|
87 | sprintf(file,"UID: %d\n",getuid());
|
---|
88 | write(fd,file,FILE_LENGTH);
|
---|
89 |
|
---|
90 | memset(file,'\0',FILE_LENGTH);
|
---|
91 | sprintf(file,"Getcwd: ");
|
---|
92 | write(fd,file,FILE_LENGTH);
|
---|
93 |
|
---|
94 | memset(file,'\0',FILE_LENGTH);
|
---|
95 | getcwd(file,FILE_LENGTH);
|
---|
96 | strcat(file,"\n");
|
---|
97 | write(fd,file,FILE_LENGTH);
|
---|
98 |
|
---|
99 | memset(file,'\0',FILE_LENGTH);
|
---|
100 | sprintf(file,"argv[1] - job_id: %s\n",argv[1]);
|
---|
101 | write(fd,file,FILE_LENGTH);
|
---|
102 |
|
---|
103 | memset(file,'\0',FILE_LENGTH);
|
---|
104 | sprintf(file,"argv[2] - user_arg: %s\n",argv[2]);
|
---|
105 | write(fd,file,FILE_LENGTH);
|
---|
106 |
|
---|
107 | memset(file,'\0',FILE_LENGTH);
|
---|
108 | sprintf(file,"argv[3] - state: %s\n",argv[3]);
|
---|
109 | write(fd,file,FILE_LENGTH);
|
---|
110 |
|
---|
111 | memset(file,'\0',FILE_LENGTH);
|
---|
112 | sprintf(file,"argv[4] - exit_status: %s\n\n",argv[4]);
|
---|
113 | write(fd,file,FILE_LENGTH);
|
---|
114 |
|
---|
115 | close(fd);
|
---|
116 |
|
---|
117 | return 0;
|
---|
118 | }
|
---|