Help required on process in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required on process in unix
# 1  
Old 08-26-2008
Help required on process in unix

What are some ways to tell if a given file is presently being used
by a process? How can you tell what sort of access the process has
to the file (read from, written to, filehandle held open, etc)?
Can more than one process access the file at the same time?
# 2  
Old 08-26-2008
Hammer & Screwdriver take a look at lsof

Do a
Code:
>man lsof

Maintenance Procedures                                    LSOF(8)



NAME
     lsof - list open files

SYNOPSIS
     lsof [ -?abChlnNOPRstUvVX ] [ -A A ] [ -c c ] [  +c  c  ]  [
     +|-d d ] [ +|-D D ] [ +|-f [cfgGn] ] [ -F [f] ] [ -g [s] ] [
     -i [i] ] [ -k k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o  [o]
     ]  [  -p  s  ] [ +|-r [t] ] [ -S [t] ] [ -T [t] ] [ -u s ] [
     +|-w ] [ -x [fl] ] [ -z [z] ] [ -- ] [names]

# 3  
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question