tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: ron_barrett () corp ! cubic ! com
To: tru64-unix-managers
Subject: SUMMARY: A belated fuser for Digital UNIX summary
Date: Mon, 29 Jan 1996 15:00:57 +0000	[thread overview]
Message-ID: <96076327921544.tru64-unix-managers.marc@archive.invalid> (raw)

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

Hugh Messenger	hugh@foo.garply.com
Tonny Madsen	Tonny.Madsen@netman.dk
Dave Thompson	Thompsond@wellington.ecnz.co.nz
Darren Bock	bock@pacstar.com.au
Johannes Grosen	grosen@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@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@corp.cubic.com
Date: 1/29/96
Time: 3:00:57 PM
-------------------------------------

                 reply	other threads:[~1996-01-29 15:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

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