File: 2gnash.c

package info (click to toggle)
lrslib 0.42c-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,220 kB
  • ctags: 922
  • sloc: ansic: 7,531; xml: 555; makefile: 91
file content (73 lines) | stat: -rw-r--r-- 2,562 bytes parent folder | download | duplicates (2)
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
// 2gnash.c     v1.0  Jan 15, 2009

// Hack of nlrs.c by Conor Meagher to run lrs simultaneously on n processors for n input files
// runs gnash on input files A B in both orders simultaneously, terminating when first proc finishes
// output goes in third argument if any, else in file: out

#include <sys/wait.h>
       #include <stdlib.h>
       #include <unistd.h>
       #include <stdio.h>

       int main(int argc, char *argv[])
	       {
                  pid_t cpid[argc - 1], w;
		  char buffer [250];	
                  int status,l,j;
                  if (argc < 3 || argc > 4) {
                      printf("Usage: 2gnash A B [outfile]\n");
                      return(0);
                      }
		  for(l = 1; l < 3; l++) {  
	              cpid[l -1] = fork();
	              if (cpid[l -1] == -1) {
		          perror("fork");
		          exit(EXIT_FAILURE);
		      }
		      if(cpid[l-1] == 0) {
			 //forked threads
			// n= sprintf(buffer, "lrs %s > out%i", argv[l], l);
                         if(l==1) {
                              int n= sprintf(buffer, "gnash %s %s > out%i", argv[1], argv[2], l);
                         }
                         else     {
                              int n= sprintf(buffer, "gnash %s %s > out%i", argv[2], argv[1], l);
                         }

			 int i=system(buffer);
                          _exit(0);
		      }
		  }
		  // main thread
		  w = wait(&status);
		  for(j = 1; j < 3; j++) {
		      if(w == cpid[j-1]) {
			  // this child finished first
                          if(j==1)
			      printf("gnash %s %s   finished first\n", argv[1], argv[2]);
                          else {
			      printf("gnash %s %s   finished first\n", argv[2], argv[1]);
			      printf("player numbers will be reversed in output\n");
                               }
                           if(argc == 4) {
			       printf("output file: %s\n", argv[3]);
			       int n = sprintf(buffer, "/bin/mv -f out%i %s", j, argv[3]);
                           }
                           else  {
			        printf("output file: out\n", argv[2], argv[1]);
			        int n = sprintf(buffer, "/bin/mv -f out%i out", j);
                           }
			  int i = system(buffer);
		      } else {
			 // printf("terminating lrs of file %s\n", argv[j]);
			  int n = sprintf(buffer, "/bin/rm -f out%i", j);
			  int i = system(buffer);
		      }
		  }
                  printf("the other process will be ");   /*...will be killed */
                  fflush(stdout);

		  kill(0,9);

exit(EXIT_SUCCESS);
}