Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4e663e7b9ec920b2c48c9ba2d9d5837d835755f2
[simgrid.git] / tools / tesh2 / examples / background.tesh
1
2 $ rm -rf temp_testdir
3 $ mkdir temp_testdir
4 $ cd temp_testdir
5
6 < #include <unistd.h>
7 < #include <stdlib.h>
8 < #include <stdio.h>
9 < #include <sys/types.h>
10 < #include <sys/stat.h>
11 < #include <fcntl.h>
12
13 < #ifdef __MINGW32__
14 < #define sleep _sleep
15 < #endif
16 <                    
17 < int main() {
18 <       char buff[2048];
19 <       char* p;
20 <       int got;
21 <       int in;
22 <       int w;
23 <       int tgot = 0;
24 <       
25 <       sleep(1);
26 <       
27 <       if((in = open("tmp_fich",O_RDONLY|O_CREAT)) == -1){
28 <               perror("Cannot open tmp_fich");
29 <               exit(1);
30 <       }
31 <       
32 <       while (1) {
33 <               if((got = read(in,&buff,2048)) == -1)
34 <                       perror("Error while reading");
35 <               else if(got == 0 && tgot != 0)
36 <                       break; /* EOF */
37 <               
38 <               if(!got)
39 <                       continue;                       
40 <               
41 <               p = buff;
42 <
43 <               tgot += got;
44 <               
45 <               while(got) {
46 <                       if((w = write(1, p , got)) < 0) {
47 <                               perror("Error while writing");
48 <                               exit(1);
49 <                       }       
50 <                       
51 <                       p += w;
52 <                       got -= w;
53 <               }
54 <       }
55
56 <       return 0;
57 < }
58 $ cat > delayed_cat.c
59
60 $ gcc -Wall -o delayed_cat delayed_cat.c
61
62 & ./delayed_cat 
63 > TOTO
64
65 < TOTO
66 $ cat > tmp_fich
67
68 $ sleep 2
69 $ cd ..
70 $ rm -rf temp_testdir
71