Operating System - HP-UX
1833785 Members
3978 Online
110063 Solutions
New Discussion

Does a process have an open file handle?

 
SOLVED
Go to solution
Ameer Dixit
Advisor

Does a process have an open file handle?

Hello,
I'm trying to write a script to clean up some logfiles, but I need to be certain no active processes have an open filehandle. I thought I could do this easily using lsof ("lsof filename" should list any processing using the file), but the command just coredumps on my 11i server. I got the lsof package from the HPUX porting site, for the 11.0 and 11i OS's. Does someone know of a different lsof I should use, or have another solution to my problem?

Thanks for your help.
9 REPLIES 9
Robert-Jan Goossens
Honored Contributor

Re: Does a process have an open file handle?

Hi,

11i as in 11.11 or 11.23 ?

Could you post a uname -a

Robert-Jan
Ameer Dixit
Advisor

Re: Does a process have an open file handle?

Hello, 11.11. Here's an swlist on my depot of lsof and a chatr on the lsof executable.

cfcert1:/opt/fcrtv3/log #> uname -a
HP-UX cfcert1 B.11.11 U 9000/800 122901577 unlimited-user license

cfcert1:/opt/fcrtv3/log #> swlist | grep -i lsof
lsof 4.74 lsof

cfcert1:/usr/local/bin #> chatr lsof
chatr(warning): dl_header_ext.size != sizeof(dl_header_ext). Please update your
version of the chatr tool.
lsof:
shared executable
shared library dynamic path search:
SHLIB_PATH enabled first
embedded path disabled second Not Defined
shared library list:
dynamic /usr/lib/libnsl.1
dynamic /usr/lib/libc.2
shared library binding:
deferred
global hash table disabled
plabel caching disabled
global hash array size:1103
global hash array nbuckets:3
shared vtable support disabled
static branch prediction disabled
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation disabled
text segment locking disabled
data segment locking disabled
third quadrant private data space disabled
fourth quadrant private data space disabled
third quadrant global data space disabled
data page size: D (default)
instruction page size: D (default)
nulptr references enabled
shared library private mapping disabled
shared library text merging disabled
Robert-Jan Goossens
Honored Contributor

Re: Does a process have an open file handle?

I wondering about all the run time dependecies ??

lsof Run-time dependencies: bison flex gcc gettext libiconv m4

Attached a older 64 bits version to this thread should work on your 11.11 version.

Regards,
Robert-Jan

Ameer Dixit
Advisor

Re: Does a process have an open file handle?

Thank you. I've downloaded it to my PC as a .zip, but Winzip doesn't know what it is. Should be a .tgz or ? Thanks again.
A. Clay Stephenson
Acclaimed Contributor

Re: Does a process have an open file handle?

File handles belong to another operating system's lexicon; in UNIX speak the term is "file descriptor" --- and don't you forget it. You should download the lsof source and compile/link it yourself. It's quite easy.
If it ain't broke, I can fix that.
Ameer Dixit
Advisor

Re: Does a process have an open file handle?

OK, I can certainly give that a try. Is there a ITRC link or other good place to look for instructions? I've never had to manually compile anything on HPUX (we've come so far it mades admins really lazy).
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Does a process have an open file handle?

The instructions are included with the source code download. Generally, you binary download the gzip'ed file into a directory; gunzip it, and then untar it. Next cd into the untar'ed direcory and run 'configure'. You then execute 'make'.
If it ain't broke, I can fix that.
D Block 2
Respected Contributor

Re: Does a process have an open file handle?

try this one:

lsof | grep filename

note: give a filename not a full directory path.

also:

lsof > /tmp/lsof.out

grep filename /tmp/lsof.out

then you can run awk or cut tools on this file to get the pid.. and then you can status the pid -- to see if it is still running..

Golf is a Good Walk Spoiled, Mark Twain.
Eknath
Trusted Contributor

Re: Does a process have an open file handle?

Hi Amit,

Can you try using fuser in your script if you are still facing problems with lsof

Cheers!!!
eknath