I have a shell script and a c program
Code:
        #!/bin/bash
        for i in `seq 1 10000`
        do
        (flock -x 200                   // what is 200?
           ./taskA
        ) 200> lockfile
        done
in the C program, related code snippets are:

Code:
        int fd = open("lockfile", O_WRONLY|O_CREAT); // what permission should I put here?
        for(i=0;i<10000;i++){
          if(fd==-1)
                printf("open file fails\n");

          if(flock(fd, LOCK_EX)==0 ){      // lock the file
                taskB(); // here is what I want to do
                }

          if (flock(fd, LOCK_UN)==0)  // after finishing those tasks, unlock it
          {
                printf("C unlock\n");
          }
         }
I want to run the shell script and C program on the same host
and I hope they can run `taskA` and `taskB` at alternately, in different time
but I'm not familiar with flock, so there are some permission problems or open file failures

for example, if I run the C program and let it finish and then run it again, I get
"open file failure"
and the permission is
Code:
    ---xr-x--T 1 esolve 200036    0 May  6 02:18 lockfile
how to modify the scripts and code?
thanks!