SUMMARY: A belated fuser for Digital UNIX summary

From: <ron_barrett_at_corp.cubic.com>
Date: Mon, 29 Jan 96 15:00:57 PST

Jefe's,
        My apologies for my delayed summary. My thanks to:

Hugh Messenger hugh_at_foo.garply.com
Tonny Madsen Tonny.Madsen_at_netman.dk
Dave Thompson Thompsond_at_wellington.ecnz.co.nz
Darren Bock bock_at_pacstar.com.au
Johannes Grosen grosen_at_dilbert.cc.ndsu.nodak.edu

There are two good options for finding open file status on Digital UNIX, lsof
and fuser. lsof is available from
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof (among other places) and fuser is
a wrapper around the libc fuser() routine provided by Darren and included
below:

/*
 * fuser - Reports PIDs and UIDs for files, file systems and/or the devices
attached to them.
 * This is so simple it makes you wonder why DEC didn't bother to
do it themselves.
 *
 * Produced at Pacific Star Communicatons
 *
 * History :
 * 31/12/95 J.Rouse Initial version
 * 31/12/95 D.Bock Added in flags for process type.
 */

#include <stdio.h>
#include <sys/sysinfo.h>
#include <sys/signal.h>
#include <sys/fuser.h>


main(argc,argv)
int argc;
char **argv;
{
  char *file;
  f_user_t fuser_array[10000]; /* Arbitrary array size */
  int i,fuser_count=0;

  if ( argc != 2 ) {
    printf("Usage: fuser FILE\n");
    exit(1);
  }

  file = argv[1];

  /* No buffering */
  setbuf(stdout,NULL);

  fuser_count=fuser(file, 0l, fuser_array, (long) sizeof (fuser_array));
  if ( fuser_count <0 ){
    exit (1);
  } else {
    printf("%s:\n",file);
    if (fuser_count > 0 ){
      for ( i=0; i < fuser_count; i++){
        printf("%d", fuser_array[i].fu_pid);
        if (fuser_array[i].fu_flags & (F_CDIR|F_RDIR))
          printf("c");
        else if (fuser_array[i].fu_flags & (F_PDIR))
          printf("p");
        else if (fuser_array[i].fu_flags & (F_TTY))
          printf("t");
        else if (fuser_array[i].fu_flags & (F_TRACE))
          printf("tr");
        printf(" ");
      };
    };
    printf("\n");
  }

  exit(0);
}

---
   *
  /|\   Darren Bock                           E-mail: <dbock_at_pacstar.com.au>
 *-+-*  Pacific Star Communications Pty Ltd   Tel:    +61 7 3405 5639
  \|*   GPO Box 2453                          Fax:    +61 7 3405 5095
   *    Brisbane Qld 4001                     Mob:
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
*  Pacific Star will not be held responsible for this transmission  *
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
-------------------------------------
Name: Ron Barrett
E-mail: ron_barrett_at_corp.cubic.com
Date: 1/29/96
Time: 3:00:57 PM
-------------------------------------
Received on Tue Jan 30 1996 - 00:49:15 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT