Find and lsof | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Find and lsof

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-12-2009
Arunprasad Arunprasad is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 9 October 2014, 7:41 PM EDT
Location: syn chen
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Java Find and lsof

Hi All,

My target is to find the biggest files opened by any process and from that i have to find process id and the corresponding file also.

To get the process id which is accessing the biggest file in the given file system, i am using the below command.

lsof -s /home/arun/my_work | awk '{print $7,$2}'| sort -n | tail -1 | awk '{print $2}'

Now i have to get the file name with complete path.
How can i achieve this? [with find command or whatever]
Please help.


Sponsored Links
    #2  
Old 02-16-2009
gauravacl gauravacl is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 17 August 2009, 3:25 AM EDT
Location: India
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Arun,

If you are able to get the PID of the process you are concerned with then you get the "Files belonging to PID" using following command

lsof -p <PID>
Sponsored Links
    #3  
Old 02-16-2009
Arunprasad Arunprasad is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 9 October 2014, 7:41 PM EDT
Location: syn chen
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Java

Hi gauravacl,

PID is "1425492", and now i want to find the exact file which is bigger in size and also it is opened by the process id. But when i tried your option i am getting the output as below,

myserv123>lsof -p 1425492
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sas 1425492 ampsys cwd VDIR 46,42001 0 4043309312 /home/usr/SAS/IntTech (/dev/vx/dsk/)
sas 1425492 ampsys 0r VCHR 2,2 0t0 16628 /dev/null
sas 1425492 ampsys 1w FIFO 0xf1000100b2a35eb0 0
sas 1425492 ampsys 2w FIFO 0xf1000100b2a35eb0 0
sas 1425492 ampsys 3u IPv4 0xf10002000cabc398 0t0 TCP *:* (CLOSED)
sas 1425492 ampsys 5u unix 0xf10002000cbc7008 0t0 ->0xf10002000142c408
sas 1425492 rampsys 8u unix 0xf10002000ce2d808 0t0 ->0xf10002000d809008


It is giving many lines and i cannot see the exact file which is bigger in the file system..

My Problem and target is:
Have to find the biggest file or fastly growing file in the file system and from that take the process id and the file name (with complete path). Then my action is to send a mail to corresponding user and have to kill the process by process id and have to remove the file (bigger or growing one which belongs to the process id).

Please help me.
Thanks for your help.
    #4  
Old 02-16-2009
Arunprasad Arunprasad is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 9 October 2014, 7:41 PM EDT
Location: syn chen
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Java

Hi gauravacl,

PID is "1425492", and now i want to find the exact file which is bigger in size and also it is opened by the process id. But when i tried your option i am getting the output as below,

myserv123>lsof -p 1425492
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sas 1425492 ampsys cwd VDIR 46,42001 0 4043309312 /home/usr/SAS/IntTech (/dev/vx/dsk/)
sas 1425492 ampsys 0r VCHR 2,2 0t0 16628 /dev/null
sas 1425492 ampsys 1w FIFO 0xf1000100b2a35eb0 0
sas 1425492 ampsys 2w FIFO 0xf1000100b2a35eb0 0
sas 1425492 ampsys 3u IPv4 0xf10002000cabc398 0t0 TCP *:* (CLOSED)
sas 1425492 ampsys 5u unix 0xf10002000cbc7008 0t0 ->0xf10002000142c408
sas 1425492 rampsys 8u unix 0xf10002000ce2d808 0t0 ->0xf10002000d809008

I can see many lines, i want the file which growing faster or the bigger one, which belongs to the process id.

My Problem and target is:
Have to find the biggest file or fastly growing file in the file system and from that take the process id and the file name (with complete path). Then my action is to send a mail to corresponding user and have to kill the process by process id and have to remove the file (bigger or growing one which belongs to the process id).
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
lsof equivalent in HP-UX deo_kaustubh HP-UX 1 01-27-2009 11:16 AM
lsof in solaris champak Shell Programming and Scripting 1 02-01-2008 08:07 AM
lsof ??? marc UNIX for Dummies Questions & Answers 6 06-23-2006 02:57 AM
lsof output skotapal UNIX for Dummies Questions & Answers 2 01-14-2003 11:12 AM
lsof jacl Filesystems, Disks and Memory 1 06-11-2002 09:27 PM



All times are GMT -4. The time now is 08:11 AM.