無效的參數我米,文件鎖定在工作進程間通信 下面的代碼中的bug我... 當通過終端的Macintoshfnctl:用C
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc , char *argv[])
{
// l_type , l_whence , l_start , l_len , l_pid
struct flock f1 = {F_WRLCK , SEEK_SET , 0 , 0 , 0};
int fd;
f1.l_pid = getpid() ;
// if command line arguments , then assign a Read Lock
if (argc > 1)
{
f1.l_type = F_RDLCK ;
}
if ((fd = open("lockdemo.c", O_RDWR)) == -1)
{
perror("open");
exit(1);
}
printf("Press <RETURN> to try to get lock");
getchar() ;
printf("trying to get lock...");
if (fcntl(fd, F_SETLKW , &f1) == -1)
{
perror("fcntl");
exit(1);
}
printf("got lock !\n");
printf("Press <RETURN> to release lock:");
getchar();
f1.l_type = F_UNLCK ; //set to unlock same region
if (fcntl(fd, F_SETLK , &f1) == -1)
{
perror("fcntl");
exit(1);
}
printf("Unlocked .. \n");
close(fd);
return 0;
}
運行,但出現以下錯誤: fnctl :無效的參數
plz幫助我在這個問題...
_Which_'fcntl'調用它,讓這個錯誤嗎? –
「試圖獲得塊」之後的一個 – Subbu
先生,你有gud信譽點......你會爲c程序員創建一個聊天室......已經有一個房間 ..但不活動......並且不允許我問候隊列......所以,根據程序PLZ ..... –
Subbu