Betwen script race condition and C binary

I have a C program that writes data to a file.

Program C does not keep the file open at run time, it simply opens the file with fopen ("myfile.txt","a")) and writes some data, and then closes the file.

On the other hand, I have a script file that can simultaneously perform 2 actions in a single file using a binary C program:

  • He can delete the file

  • he can add some lines to the file using the command

    echo "some data" >> file
    

Is there a risk of the state of the betwen script race and the C binary program? Can Linux ioctl handle this problem?

If there is a risk of race conditions, how to check in C and shell before processing the file?

+4
2

, - "", . (, - ).

:

  • , fcntl, flock (., , qst)
  • "lock ", /some/path/file.lck ( (pid) - ) (/ ) . "lock-file" ). , , "" shell-). (, ).
+8

- C .

- . , , bash script. , script, .

, posix chmod 1000 ( 01000, ). bash, , find, . foo.txt find . -name foo.txt -perm 1000 , find . ( unix.com).

0

All Articles