next up previous
Next: Propagating Signals Up: No Title Previous: Shell Scripts...Communication

Shell Scripts...Locking and Flushing

When two or more processes are accessing the same file, one must take care to ensure that the file is locked while a record is being written, and that the file is flushed, to ensure that the disk image is updated. Locking is handled by the lockf call, as in the example:
fd=open("output",O_CREAT|O_APPEND); 
f=fdopen(fd,"a"); 
....  
if (lockf(fd,F_LOCK,0)==-1) perror("lock failed on output");
fprintf(f,"some data %g\n",x);
fflush(f); lockf(fd,F_ULOCK,0); 
...



Russell Standish
2001-05-04