Chung Kil Kim wrote:

>   while (1)
>     {
>       if (-1 == fcntl (fd_no, F_GETLK, &lock_info))  /* get lock info */
>         {
>           perror ("fcntl()");
>           exit (1);
>         }

> I run this program. But end with printing following message.
> fcntl(): Invalid argument
> 
> What is the wrong?

What is wrong is that you don't understand what the F_GETLK fcntl()
option is for.

You are supposed to fill in the lock_info structure with the details
of a lock that you wish to obtain.

If you could obtain the requested lock, then lock_info.l_type is set
to F_UNLCK, and the other members of lock_info are unchanged.

If there is another lock in existence which prevents you from
obtaining the requested lock, then the details of that lock are
returned in lock_info.

You haven't filled in lock_info before calling fcntl(), so the lock
that it describes is almost certainly going to be invalid, resulting
in fcntl() returning -1 and setting errno to EINVAL.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to