Sponsored Content
Top Forums Shell Programming and Scripting Help required on process in unix Post 302229228 by aigles on Tuesday 26th of August 2008 01:08:25 PM
Old 08-26-2008
On an AIX box (not sure for other Unix flavour) , you can also use the fuser command.
Code:
Commands Reference, Volume 2, d - h
fuser Command

Purpose

Identifies processes using a file or file structure.
Syntax

fuser [ -c | -d | -f ] [ -k | -K { SignalNumber | SignalName }] [ -u ] [ -x ] [ -V ]File ...
Description

The fuser command lists the process numbers of local processes that use the local or remote files specified by the File parameter. For block special devices, the command lists the processes that use any file on that device.

Each process number is followed by a letter indicating how the process uses the file:
c 	Uses the file as the current directory.
e 	Uses the file as a program's executable object.
r 	Uses the file as the root directory.
s 	Uses the file as a shared library (or other loadable object).

The process numbers are written to standard output in a line with spaces between process numbers. A new line character is written to standard error after the last output for each file operand. All other output is written to standard error.

The fuser command will not detect processes that have mmap regions where that associated file descriptor has since been closed.
Flags

-c 	Reports on any open files in the file system containing File.
-d 	Implies the use of the -c and -x flags. Reports on any open files which have been unlinked from the file system (deleted from the parent directory). When used in conjunction with the -V flag, it also reports the inode number and size of the deleted file.
-f 	Reports on open instances of File only.
-K SignalNumber | SignalName 	Sends the specified signal to each local process. Only the root user can kill a process of another user. Signal can be specified as either a signal name, such as -9 or KILL for the SIGKILL signal. Valid values for SignalName are those which are displayed by the kill -l command.
-k 	Sends the SIGKILL signal to each local process. Only the root user can kill a process of another user.
Note:
fuser -k or -K might not be able to detect and kill new processes that are created immediately after the program starts to run.
-u 	Provides the login name for local processes in parentheses after the process number.
-V 	Provides verbose output.
-x 	Used in conjunction with -c or -f, reports on executable and loadable objects in addition to the standard fuser output.
Examples

   1. To list the process numbers of local processes using the /etc/passwd file, enter:

      fuser /etc/passwd

   2. To list the process numbers and user login names of processes using the /etc/filesystems file, enter:

      fuser -u /etc/filesystems

   3. To terminate all of the processes using a given file system, enter:

      fuser -k -x -u -c /dev/hd1 

      or

      fuser -kxuc /home

      Either command lists the process number and user name, and then terminates each process that is using the /dev/hd1 (/home) file system. Only the root user can terminate processes that belong to another user. You might want to use this command if you are trying to unmount the /dev/hd1 file system and a process that is accessing the /dev/hd1 file system prevents this.
   4. To list all processes that are using a file which has been deleted from a given file system, enter:

      fuser -d /usr

Files

/dev/kmem 	Used for the system image.
/dev/mem 	Also used for the system image.
Related Information

The kill command, killall command, mount command, and ps command.

For more information about the identification and authentication of users, discretionary access control, the trusted computing base, and auditing, refer to Security.

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX PATH info required PLEASE HELP (I'm new to unix)

I need to know how to enter a unix path in a cgi script for a guest book: example: My URL is http://www.kitachi.info I have an html file in the main folder on my site, the file is called : gbook.html what would the correct unix path for this file be ??? the part of the script... (1 Reply)
Discussion started by: akitachi
1 Replies

2. Programming

UNIX Internals, Help required...

I know UNIX user level commands, shell scripts. But i have no idea about kernel level programming and networking. I know the terms semaphore,IPC,socket programming. But i don't know in details what are these. I need to know the following. 1. Unix kernel level programming. 2. Unix Internals. 3.... (4 Replies)
Discussion started by: digdarshan
4 Replies

3. UNIX for Dummies Questions & Answers

Help Required in Unix Command

Hi All, Can anyone please help me in unix command Query: ==== File contains data along with date and time stamp like, .. Date: 08:23:2005 01:00:00 method: xyz init variables Date 08:23:2005 01:00:01 method: xyz finished init variable .... (2 Replies)
Discussion started by: thaduka
2 Replies

4. HP-UX

urgent help required on changing process priority using nice

Hi folks, Hope you can help me. I have a process that is currently running at nice 20 and need it to run faster (-10?). How do I change the process using nice? I have the process number and thought it would be along the lines of; nice -10 process_id but it doesn't seem to like that. (1 Reply)
Discussion started by: gshuttleworth
1 Replies

5. UNIX for Advanced & Expert Users

Required unix command!!!

Hi, In a file I have data like... -rw-r----- 1 ftpuser users 1036695 Jul 6 14:59 ./APRIL 2007/Ujjain/My Disc (D)/9565DW07.04B -rw-r----- 1 ftpuser users 124080 Jul 6 14:59 ./APRIL 2007/Vadodara/vad_APRIL07/2082DW07.04B The above data is extracted using "find . -name... (12 Replies)
Discussion started by: ronald_brayan
12 Replies

6. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

7. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

8. Shell Programming and Scripting

Unix script required

I have a file 123.txt which is aasaasas=1 bsasasasasa=2 sawqas=3 I want my output to be 1 2 3 I am new to scripting can some1 help me out. (14 Replies)
Discussion started by: karthikkasarla
14 Replies

9. Shell Programming and Scripting

Script to process file from a directory and grep the required content and print

Hi All, below script reads the perticular files from the directory. Am trying to fetch status and print them in the required format. It needs to read line and search for string "Passed/Failed" and print them under correct sub header. script : BASE_DIR=/tmp/test/REPORT/CollectReport #... (16 Replies)
Discussion started by: Optimus81
16 Replies

10. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies
FSTAT(8)						      System Manager's Manual							  FSTAT(8)

NAME
fstat - file status SYNOPSIS
fstat [ -u user ] [ -p pid ] [ filename... ] DESCRIPTION
Fstat identifies open files. A file is considered open if a process has it open, if it is the working directory for a process, or if it is an active pure text file. If no options are specified, fstat reports on all open files. Options: -u Report all files open by a specified user. -p Report all files open by a specified process id. filename... Restrict reports to the specified files. If the file is a block special file, fstat additionally reports on any open files on that device, treating it as a mounted file system. The following fields are printed USER The username of the owner of the process. CMD The command name of the process. PID The process id. FD The file number in the per-process open file table. The special names "text" and "wd" mean that the file is the pure text inode or the working directory for the process. If the file number is followed by an asterick (*), then the file is not an inode, but either a socket, fifo, or has an error of some kind. In this case the rest of the entry is variable format, doesn't correspond to the rest of the headings, and is enclosed in parenthesis. The following paragraph describing sockets will explain the variable format. DEVICE Major minor number of the device this file exists on. INODE The inode number of the file. SIZE The size in bytes of the file. TYPE The type of the file. (see sys/file.h) Sockets The formating of open sockets depends on the protocol domain. In all cases the first field is the domain name, the second field is the socket type (stream, dgram, etc), and the third is the socket flags field (in hex). The remaining fields are protocol dependent. For tcp, it is the address of the tcpcb, and for udp, the inpcb (socket pcb). For unix domain sockets, its the address of the socket pcb and the address of the connected pcb (if connected). Otherwise the protocol number and address of the socket itself are printed. The idea is not to duplicate netstat, but to make available enough information for further analysis. For example, the addresses mentioned above are the addresses which the "netstat -A" command would print for tcp, udp, and unixdomain. Note that since pipe(2) is implemented with sock- ets, a pipe appears as a connected unix domain stream socket. A unidirectional unix domain socket indicates the direction of flow with an arrow ("<-" or "->"), and a full duplex socket shows a double arrow ("<->"). BUGS
Socket information clutters the output. Since fstat takes a snapshot of the system, it is only correct for a very short period of time. SEE ALSO
ps(1), pstat(8) 4th Berkeley Distribution December 12, 1987 FSTAT(8)
All times are GMT -4. The time now is 02:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy