aboutsummaryrefslogtreecommitdiffstats
path: root/diskdev_cmds/fuser.tproj
diff options
context:
space:
mode:
Diffstat (limited to 'diskdev_cmds/fuser.tproj')
-rw-r--r--diskdev_cmds/fuser.tproj/fuser.1200
-rwxr-xr-xdiskdev_cmds/fuser.tproj/fuser.pl92
2 files changed, 292 insertions, 0 deletions
diff --git a/diskdev_cmds/fuser.tproj/fuser.1 b/diskdev_cmds/fuser.tproj/fuser.1
new file mode 100644
index 0000000..fcaf5a2
--- /dev/null
+++ b/diskdev_cmds/fuser.tproj/fuser.1
@@ -0,0 +1,200 @@
+.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
+.TH "FUSER" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
+.\" fuser
+.SH NAME
+fuser \- list process IDs of all processes that have one or more files
+open
+.SH SYNOPSIS
+.LP
+\fBfuser\fP \fB[\fP \fB-cfu\fP \fB]\fP \fIfile\fP \fB... \fP
+.SH DESCRIPTION
+.LP
+The \fIfuser\fP utility shall write to standard output the process
+IDs of processes running on the local system that have one
+or more named files open. For block special devices, all processes
+using any file on that device are listed.
+.LP
+The \fIfuser\fP utility shall write to standard error additional information
+about the named files indicating how the file is
+being used.
+.LP
+Any output for processes running on remote systems that have a named
+file open is unspecified.
+.LP
+A user may need appropriate privilege to invoke the \fIfuser\fP utility.
+.SH OPTIONS
+.LP
+The \fIfuser\fP utility shall conform to the Base Definitions volume
+of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
+.LP
+The following options shall be supported:
+.TP 7
+\fB-c\fP
+The file is treated as a mount point and the utility shall report
+on any files open in the file system.
+.TP 7
+\fB-f\fP
+The report shall be only for the named files.
+.TP 7
+\fB-u\fP
+The user name, in parentheses, associated with each process ID written
+to standard output shall be written to standard
+error.
+.sp
+.SH OPERANDS
+.LP
+The following operand shall be supported:
+.TP 7
+\fIfile\fP
+A pathname on which the file or file system is to be reported.
+.sp
+.SH STDIN
+.LP
+Not used.
+.SH INPUT FILES
+.LP
+The user database.
+.SH ENVIRONMENT VARIABLES
+.LP
+The following environment variables shall affect the execution of
+\fIfuser\fP:
+.TP 7
+\fILANG\fP
+Provide a default value for the internationalization variables that
+are unset or null. (See the Base Definitions volume of
+IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
+for
+the precedence of internationalization variables used to determine
+the values of locale categories.)
+.TP 7
+\fILC_ALL\fP
+If set to a non-empty string value, override the values of all the
+other internationalization variables.
+.TP 7
+\fILC_CTYPE\fP
+Determine the locale for the interpretation of sequences of bytes
+of text data as characters (for example, single-byte as
+opposed to multi-byte characters in arguments).
+.TP 7
+\fILC_MESSAGES\fP
+Determine the locale that should be used to affect the format and
+contents of diagnostic messages written to standard
+error.
+.TP 7
+\fINLSPATH\fP
+Determine the location of message catalogs for the processing of \fILC_MESSAGES
+\&.\fP
+.sp
+.SH ASYNCHRONOUS EVENTS
+.LP
+Default.
+.SH STDOUT
+.LP
+The \fIfuser\fP utility shall write the process ID for each process
+using each file given as an operand to standard output in
+the following format:
+.sp
+.RS
+.nf
+
+\fB"%d", <\fP\fIprocess_id\fP\fB>
+\fP
+.fi
+.RE
+.SH STDERR
+.LP
+The \fIfuser\fP utility shall write diagnostic messages to standard
+error.
+.LP
+The \fIfuser\fP utility also shall write the following to standard
+error:
+.IP " *" 3
+The pathname of each named file is written followed immediately by
+a colon.
+.LP
+.IP " *" 3
+For each process ID written to standard output, the character \fB'c'\fP
+shall be written to standard error if the process is
+using the file as its current directory and the character \fB'r'\fP
+shall be written to standard error if the process is using
+the file as its root directory. Implementations may write other alphabetic
+characters to indicate other uses of files.
+.LP
+.IP " *" 3
+When the \fB-u\fP option is specified, characters indicating the use
+of the file shall be followed immediately by the user
+name, in parentheses, corresponding to the process' real user ID.
+If the user name cannot be resolved from the process' real user
+ID, the process' real user ID shall be written instead of the user
+name.
+.LP
+.LP
+When standard output and standard error are directed to the same file,
+the output shall be interleaved so that the filename
+appears at the start of each line, followed by the process ID and
+characters indicating the use of the file. Then, if the \fB-u\fP
+option is specified, the user name or user ID for each process using
+that file shall be written.
+.LP
+A <newline> shall be written to standard error after the last output
+described above for each \fIfile\fP operand.
+.SH OUTPUT FILES
+.LP
+None.
+.SH EXTENDED DESCRIPTION
+.LP
+None.
+.SH EXIT STATUS
+.LP
+The following exit values shall be returned:
+.TP 7
+\ 0
+Successful completion.
+.TP 7
+>0
+An error occurred.
+.sp
+.SH CONSEQUENCES OF ERRORS
+.LP
+Default.
+.LP
+\fIThe following sections are informative.\fP
+.SH APPLICATION USAGE
+.LP
+None.
+.SH EXAMPLES
+.LP
+The command:
+.sp
+.RS
+.nf
+
+\fBfuser -fu .
+\fP
+.fi
+.RE
+.LP
+writes to standard output the process IDs of processes that are using
+the current directory and writes to standard error an
+indication of how those processes are using the directory and the
+user names associated with the processes that are using the
+current directory.
+.SH RATIONALE
+.LP
+The definition of the \fIfuser\fP utility follows existing practice.
+.SH FUTURE DIRECTIONS
+.LP
+None.
+.SH SEE ALSO
+.LP
+None.
+.SH COPYRIGHT
+Portions of this text are reprinted and reproduced in electronic form
+from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
+-- Portable Operating System Interface (POSIX), The Open Group Base
+Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
+Electrical and Electronics Engineers, Inc and The Open Group. In the
+event of any discrepancy between this version and the original IEEE and
+The Open Group Standard, the original IEEE and The Open Group Standard
+is the referee document. The original Standard can be obtained online at
+http://www.opengroup.org/unix/online.html .
diff --git a/diskdev_cmds/fuser.tproj/fuser.pl b/diskdev_cmds/fuser.tproj/fuser.pl
new file mode 100755
index 0000000..0784bfb
--- /dev/null
+++ b/diskdev_cmds/fuser.tproj/fuser.pl
@@ -0,0 +1,92 @@
+#!/usr/bin/perl -w
+##
+# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+##
+
+use strict;
+use Getopt::Long qw(GetOptions);
+
+sub usage {
+ print "fuser: [-cfu] file ...\n",
+ "\t-c\tfile is treated as mount point\n",
+ "\t-f\tthe report is only for the named files\n",
+ "\t-u\tprint username of pid in parenthesis\n";
+}
+
+Getopt::Long::config('bundling');
+my %o;
+unless (GetOptions(\%o, qw(c f u)) && scalar (@ARGV) > 0) {
+ usage();
+ exit(1);
+}
+
+use IO::Handle;
+STDERR->autoflush(1);
+STDOUT->autoflush(1);
+
+my $exit_value = 0;
+
+my $space = "";
+while (scalar (@ARGV)) {
+ my $file = shift @ARGV;
+ if (-e $file) {
+ my @command;
+ push(@command, q(/usr/sbin/lsof));
+ push(@command, q(-F));
+ if ($o{u}) { # Add user name
+ push(@command, q(pfL));
+ } else {
+ push(@command, q(pf));
+ }
+ push(@command, q(-f)) if ($o{f});
+ push(@command, q(--));
+ push(@command, $file);
+ # This cryptic statement will cause exec(@command) to run in the child,
+ # with the output set up correctl and LSOF's input set up correctly.
+ open (LSOF, "-|") or exec(@command);
+ my @results = <LSOF>;
+ chomp(@results);
+ # fuser man page is very explicit about stdout/stderr output
+ print STDERR $file, qq(: );
+ my $username = "";
+ foreach (@results) {
+ if (/^p(\d+)$/) {
+ if ($username) {
+ print STDERR $username;
+ $username = "";
+ }
+ print $space, $1;
+ $space = q( );
+ }
+ if (/^f(c|r)[wt]d$/) {
+ print STDERR "$1" . $username;
+ $username = "";
+ }
+ $username = "(" . $1 . ")" if (/^L(.+)$/);
+ }
+ print STDERR $username . qq(\n);
+ } else {
+ print STDERR "$0: '$file' does not exist\n";
+ $exit_value = 1;
+ }
+}
+exit($exit_value);