tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: bouchard_l () decus ! fr (Louis Bouchard - Decylog)
To: tru64-unix-managers
Subject: Orphan Summary : fuser.c
Date: Tue, 19 Mar 1996 08:40:56 +0000	[thread overview]
Message-ID: <96076330121421.tru64-unix-managers.marc@archive.invalid> (raw)

Hello,

	A while ago I saw a summary containing the source of a fuser command. 
Since it looked quite like the one I was using, I didn't bother to keep it. 
But since then, my needs have changed a bit and the limitation to F_FILE_ONLY
has been anoying me.

	I ended up rewriting my own fuser.c to allow the user to specify a
mount point, allowing the F_CONTAINED argument to be used.

	I just saw a question about a "Device Busy" on /mnt which reminded me
that I ment to send that source for a while.  So here it is.  Might be some
bugs in it. Might not be the prettiest looking "C" programming you've seen.  I
don't claim to be a "C" developper. 

	This little piece of code has been doing its job for a while now and
that's all I ask.  I taught that someone might need this.

					...Louis
----------------------------------------------------------------------------
						|	Louis Bouchard
J'aimes que ca cesse quand c'est fini. Quand	|	Ingenieur Systeme
ca recommence, ca me scie.			|	bouchard_l@decusf.fr
			R. Ducharme		|	Bouygues Telecom
						|	39-26-66-73
----------------------------------------------------------------------------

--------------------------------<Cut Here>---------------------------------

/*************************************************************************
**	Title   :	fuser						**
**	Format	:	fuser [-f | -c] <file_name|mount_point>		**
**	file    :       fuser.c						**
**	Function:	Give the file name/mount poind, PID and user	**
**			name of the process which has the file opened	**
**************************************************************************
*/
#include <stdio.h>
#include <sys/fuser.h>
#include <pwd.h>
#include <unistd.h>

#define File_Owner_Limit 10000
#define Args	"fc"

f_user_t File_Owner[File_Owner_Limit];
struct passwd *Owner_Name;

main(int argc, char *argv[])
{
int 	i,x=0;
int	c,errflg=0;
long	Fuser_Type=F_FILE_ONLY;

optarg=NULL;

while ( !errflg && ( c = getopt(argc,argv,Args)) != -1 )
	switch (c) {
	case 'c'	:
		Fuser_Type=F_CONTAINED;
		break;
	case 'f'	:
		Fuser_Type=F_FILE_ONLY;
		break;
	case '?'	:
		exit(1);
	default :
		errflg++;
	}

if ( (x=fuser(argv[optind],Fuser_Type,File_Owner,(long) sizeof (File_Owner))) > 0 )
   {
	for (i=0;i<x;i++) {
   	Owner_Name=getpwuid(File_Owner[i].fu_uid);
   	printf("FILE: %s\tPID: %d\tUSER: %s\n",argv[optind],File_Owner[i].fu_pid,Owner_Name->pw_name);
		}
   }
}

                 reply	other threads:[~1996-03-19  8:40 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