tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: Is there any way of listing all file locks AND their owners?
@ 1998-09-29 15:43 Serguei Patchkovskii
  0 siblings, 0 replies; only message in thread
From: Serguei Patchkovskii @ 1998-09-29 15:43 UTC (permalink / raw)
  To: tru64-unix-managers


Hi managers,

Yesterday, I asked for a way of listing all NFS file locks
along with the names of the machines and PIDs of the processes
holding them on a DU system. 

Anthony Talltree, Mike Iglesias, and Bruce Kelly suggested
using lslk by Vic Abell, available from:

vic.cc.purdue.edu:pub/tools/unix/lslk

It is indeed an excellent program, and does exactly what I need.

Paul Watson kindly provided a small C program (idlock.c)
capable of listing the PIDs (but not machine names) of the 
processes holding NFS locks, appended at the end of this
message. Since it works through the fcntl interface, rather
than by walking the kernel memory, it does not require root 
(or kmem) privileges and may be easier to adopt for different
unix dialects. I had not tried to compile of use this 
program.

Several people also suggested using lsof (also by Vic Abell).
Unfortunately, lsof cannot list locks on files which are
not open anywhere (which happened to be the case for us),
and cannot list locks on files located on NFS file systems 
(except on Solaris), which makes it rather useless for us.

Many thanks to everybody who had answered.

Regards,

/Serge.P

--- idlock.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

main()
{
        int desc,i;
        char *file = (char *)malloc(100);
        struct flock verrou;
        printf("Enter the name of the file : ");
        scanf("%s",file);
        printf("Overview of the locks on the file\n");
        printf("Beginning...\n");
        if ((desc=open(file,O_RDWR))==-1)
        {
                printf("open (R and W) failed during opening %s\n",file);
                exit(-1);
        }
        verrou.l_type=F_WRLCK;
        verrou.l_whence=0;
        verrou.l_len=0;
        verrou.l_start=0;
        if (fcntl(desc,F_GETLK,&verrou))
                {
                        perror("Lock error : fcntl function");
                        exit(-1);
                }
        if (verrou.l_type == F_UNLCK)
          printf("...no locks on your file !\n");
        else
          printf("...your file is locked by pid : %d !\n",verrou.l_pid);

}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-09-29 15:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-09-29 15:43 SUMMARY: Is there any way of listing all file locks AND their owners? Serguei Patchkovskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox