From owner-freebsd-standards Mon Mar 18 19: 0:43 2002 Delivered-To: freebsd-standards@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 8B5C837B41A for ; Mon, 18 Mar 2002 19:00:03 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2J303496654; Mon, 18 Mar 2002 19:00:03 -0800 (PST) (envelope-from gnats) Received: from descent.robbins.dropbear.id.au (044.a.006.mel.iprimus.net.au [210.50.44.44]) by hub.freebsd.org (Postfix) with ESMTP id 845D037B400 for ; Mon, 18 Mar 2002 18:59:41 -0800 (PST) Received: (from tim@localhost) by descent.robbins.dropbear.id.au (8.11.6/8.11.6) id g2J2vM401093; Tue, 19 Mar 2002 13:57:22 +1100 (EST) (envelope-from tim) Message-Id: <200203190257.g2J2vM401093@descent.robbins.dropbear.id.au> Date: Tue, 19 Mar 2002 13:57:22 +1100 (EST) From: "Tim J. Robbins" Reply-To: "Tim J. Robbins" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: standards/36076: Implementation of POSIX fuser command Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG >Number: 36076 >Category: standards >Synopsis: Implementation of POSIX fuser command >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Mar 18 19:00:02 PST 2002 >Closed-Date: >Last-Modified: >Originator: Tim J. Robbins >Release: FreeBSD 4.5-STABLE i386 >Organization: >Environment: System: FreeBSD descent.robbins.dropbear.id.au 4.5-STABLE FreeBSD 4.5-STABLE #8: Tue Mar 19 08:46:39 EST 2002 tim@descent.robbins.dropbear.id.au:/usr/obj/usr/src/sys/DESCENT i386 >Description: FreeBSD is missing the P1003.1-2001 fuser command. >How-To-Repeat: N/A >Fix: A shell script wrapper around the more powerful fstat utility that modifies its inputs and outputs to act like fuser. Script was tested with FreeBSD /bin/sh and AT&T ksh93 from ports. # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # fuser.1 # fuser.sh # echo x - fuser.1 sed 's/^X//' >fuser.1 << 'END-of-fuser.1' X.\" Copyright (c) 2002 Tim J. Robbins. X.\" All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.\" $FreeBSD$ X.\" $Id: fuser.1,v 1.2 2002/02/17 23:14:44 tim Exp $ X.\" X.Dd February 9, 2002 X.Dt FUSER 1 X.Os X.Sh NAME X.Nm fuser X.Nd list process IDs of all processes that have one or more files open X.Sh SYNOPSIS X.Nm X.Op Fl c | f X.Op Fl mu X.Op Fl M Ar core X.Op Fl N Ar system X.Ar X.Sh DESCRIPTION XThe X.Nm Xutility writes to standard output the process IDs of processes that Xhave one or more of the specified X.Ar file Xarguments open. X.Pp XIf a X.Ar file Xargument is a block special device, all processes using any file on that Xdevice are listed. X.Pp XAdditional information about the open files is written to standard error. X.Pp XThe options are as follows: X.Bl -tag -width indent X.It Fl M Ar core XExtract values associated with the name list from X.Ar core Xinstead of X.Pa /dev/kmem . X.It Fl N Ar system XExtract the name list from X.Ar system Xinstead of X.Pa /kernel . X.It Fl c XTreat the X.Ar file Xarguments as mount points and list all files open on these file systems. X.It Fl f XDisable special processing for block special devices. X.It Fl m XInclude information about memory mapped files. X.It Fl u XInclude the user who owns each process in the output. X.El X.Pp XThe format of the output is: X.Bl -bullet -offset indent X.It XFile or mount point name, followed by a colon X.Pq Ql \&: ; X.It XProcess ID; X.It XZero or more of the following flags, indicating how the file is being used: X.Bl -tag -width z X.It Cm c XProcess's working directory X.It Cm r XProcess's root directory X.It Cm x XExecutable text X.It Cm t XKernel trace file X.It Cm m XMemory mapped file X.El X.It XIf the X.Fl u Xoption is given, the user name of the process's owner, in parentheses. X.El X.Sh EXAMPLES XKill all processes with X.Pa foo.c Xopen: X.D1 kill `fuser foo.c` X.Sh DIAGNOSTICS X.Ex -std X.Sh SEE ALSO X.Xr fstat 1 , X.Xr ktrace 1 X.Sh STANDARDS XThe X.Nm Xutility is designed to comply with the X.St -p1003.1-2001 Xspecification. X.Sh BUGS XThe user name associated with the process's effective user ID is written Xinstead of that of the real user ID. END-of-fuser.1 echo x - fuser.sh sed 's/^X//' >fuser.sh << 'END-of-fuser.sh' X#!/bin/sh X# X# Copyright (c) 2002 Tim J. Robbins. X# All rights reserved. X# X# Redistribution and use in source and binary forms, with or without X# modification, are permitted provided that the following conditions X# are met: X# 1. Redistributions of source code must retain the above copyright X# notice, this list of conditions and the following disclaimer. X# 2. Redistributions in binary form must reproduce the above copyright X# notice, this list of conditions and the following disclaimer in the X# documentation and/or other materials provided with the distribution. X# X# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND X# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE X# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X# SUCH DAMAGE. X# X X# X# fuser - list process IDs of all processes that have one or more files open X# This is a wrapper script around fstat(1). X# X# $FreeBSD$ X# $Id: fuser.sh,v 1.2 2002/02/17 23:14:56 tim Exp $ X# X Xcflag=0 Xfflag=0 Xuflag=0 Xfstatopts="" Xwhile getopts M:N:cfmu ch; do X case $ch in X M) # Choose memory file X fstatopts="$fstatopts -M $OPTARG" X ;; X N) # Choose kernel file X fstatopts="$fstatopts -N $OPTARG" X ;; X c) # Treat as mount point X cflag=1 X ;; X f) # Show open block devices X fflag=1 X ;; X m) # Show memory mapped files X fstatopts="$fstatopts -m" X ;; X u) # Print user names X uflag=1 X ;; X esac Xdone X Xshift $(($OPTIND - 1)) Xif [ $# -eq 0 -o \( $cflag -eq 1 -a $fflag -eq 1 \) ]; then X echo "usage: fuser [-c|-f] [-mu] [-M core] [-N system] file..." >&2 X exit 64 Xfi X Xfor f in $*; do X if [ $cflag -eq 1 ]; then X fstat -f $fstatopts -- "$f" X else X mtpt=`mount | grep -we "^$f" | cut -d" " -f3` X if [ "$mtpt" != "" -a $fflag -ne 1 ]; then X fstat $fstatopts -f -- "$mtpt" X else X fstat $fstatopts -- "$f" X fi X fi | tail -n +2 | while read user cmd pid fd junk; do X echo -n "$f: " >&2 X echo -n "$pid " X case $fd in X wd) X echo -n c >&2 X ;; X root) X echo -n r >&2 X ;; X text) X echo -n x >&2 X ;; X tr) X echo -n t >&2 X ;; X mmap) X echo -n m >&2 X ;; X esac X if [ $uflag -eq 1 ]; then X echo -n "($user)" >&2 X fi X echo >&2 X done Xdone END-of-fuser.sh exit >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message