From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078721912171.tru64-unix-managers.marc@archive.invalid> From: Serguei Patchkovskii Date: Tue, 29 Sep 1998 15:43:46 +0000 To: tru64-unix-managers Subject: SUMMARY: Is there any way of listing all file locks AND their owners? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078721912171 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 #include #include #include #include #include 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); }