As a newcommer to unix-programming I have a problem using lockf().
The following code have worked on several unix-systems but not on a NCR-box
"named" : Unix System V Release 4.0 Version 3.0 (WINS)
The program starts sleeping at the lockf() function.
(truss) write(1, " B e f o r e l o c k f".., 13) = 13
fcntl(4, F_SETLKW, 0x08047AF0) (sleeping...)
Why ?
Thank you in advance.
Michael Lynggaard /Denmark
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
void main ( argc, argv )
int argc;
char **argv;
{
int fd;
char szBuffer[80+1];
printf("Waiting... Hit a key. (pid %d)", getpid());
gets(szBuffer);
umask( 002 );
fd = open( "afile.tmp", O_CREAT | O_WRONLY, 0777 );
if ( fd == -1 )
{
printf("Error in 'open'");
exit( -1 );
}
printf("Before lockf\n");
if ( lockf(fd, F_LOCK, 0L) == -1 )
{
printf("Error in 'lockf' (file may already be locked)");
exit( -1 );
}
printf("Program is running. File lock is active until you hit a key.\n");
gets(szBuffer);
close(fd);
exit( 0 );
Quote:}