views:

33

answers:

3

EDIT 1

I'm having problems using the arguments given. Maybe it is the way I'm passing my arguments through NSTask? Any suggestions as to how I can do this?

NSTask *file_Task = [NSTask new];
[file_Task setLaunchPath:@"/usr/sbin/lsof"];
[file_Task setArguments:[NSArray arrayWithObjects:@"+p", the_Pid, nil]];

Good Afternoon Fellow Coders....

I'm using the following command:

lsof +p 13812

to get the list of a files accessed by a process. The thing is it is giving me a lot of additional information that I don't want such as TYPE, DEVICE, etc.

Is there an argument that I can add to the above command so that I get ONLY the NAME?

Thank you, thank you thank you! :)

Eric

A: 

try:

lsof | tr -s ' ' | cut -d' ' -f9
jcubic
+1  A: 

lsof +p 9174 | awk '{ print $9 }'

Radomir Dopieralski
+1  A: 

You can use:

lsof -Fn +p 12345

This will output a list of lines, with the first being p followed by the process ID, and all following lines consisting of n followed by the file name.

If you'd like to quickly preprocess this, you can do something similar to the following:

lsof -Fn +p 12345 | tail -n +2 | cut -c2-

See the lsof man page for more information, specifically under the OUTPUT FOR OTHER PROGRAMS heading.

Hasturkun