Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Alex Nord <alex_nord@jabil.com>
To: Hugues Talbot <talbot@fire.syd.dms.csiro.au>
Subject: Re: equivalent of Solaris `fuser' command under DU ?
Date: 1997/02/14	[thread overview]
Message-ID: <330494BE.43C@jabil.com> (raw)
In-Reply-To: yeabu9pfkbk.fsf@fire.syd.dms.CSIRO.AU


Hugues Talbot wrote:
> 
>         Hello all Dec Unix Guru,
> 
>         I'm running DU 3.2c on an AlphaStation 200-4/233.
> I'm looking for the equivalent of the Solaris command `fuser'
> under Dec Unix.
>         I noticed that DU does have the fuser system call.  Did
> someone out there go to the trouble of making an application out of
> it?
> 
>         Thanks for any help/pointer.

Here's some quick C code I threw together.  Every now and then, it 
gives me some 'unpredictable' output (read "None at all!"), but I 
think I at least have all the core dumps worked out of it. :)

#include <stdio.h>
#include <sys/fuser.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <malloc.h>

int main(argc, argv)
int argc;
char *argv[];
{
	int x,y;
	struct f_user * wowie;
	struct f_user crap[1];
	struct passwd person;

	if (getuid() != 0)
	   {
	   fprintf (stderr,"You must be root to use %s!\n",argv[0]);
	   exit (-1);
	   }
	if (argc != 2)
	   {
	   fprintf (stderr,"Usage : fuser <filename>\n");
	   exit (-1);
	   }
	x=fuser(argv[1], 0L, crap, sizeof(struct f_user));
	if (errno == 2)
	   {
	   fprintf (stderr,"'%s' - Not Found\n",argv[1]);
	   exit (-1);
	   }
	if (x==0)
	   {
	   fprintf(stdout,"No processes are currently accessing %s\n",argv[1]);
	   exit (x);
	   }
	wowie=(struct f_user *) malloc(x*(sizeof(struct f_user)));
	x=fuser(argv[1], 0L, wowie, (long) (x * (sizeof (struct f_user))));
	for (y=0;y<x;y++)
	   {
	   person=*getpwuid(wowie[y].fu_uid);
	   fprintf(stdout,"%s (%d)    ",person.pw_name,wowie[y].fu_pid);
	   }
	fprintf(stdout,"\n");
	free(wowie);
	return (x);
}



      parent reply	other threads:[~1997-02-14  5:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-13  5:00 equivalent of Solaris `fuser' command under DU ? Hugues Talbot
1997-02-13  5:00 ` Paul Dwerryhouse
1997-02-14  5:00 ` Alex Nord [this message]
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