Hi,
I am new to mac programming, and i am facing a problem while
parsing the output of lsof command for listing the information
of pids.
Problem : Most of the time
lsof gets hang (go in a sleep mode "S+")
Steps what i am doing to parse the output of lsof for a list
of pids.
1) Getting a list of pids with the use of sysctl().
2) For each pid, storing the output of lsof in a file by
calling
popen("lsof
-F n -p PID","r");
When I am executing these lines of code in multiple threads,
then most of the time one or more than one thread gets hang i.e. it is not
coming out of the thread(my application gets hang). If I am listing the state
of processes, it has been observed that pid of some processes specially of lsof
is in sleep mode (S+), and if we see its more details, then it is found that lsof
processes are in sleep mode those are executed for a PID which is not existed.
We know that lsof return with zero output, if we call it for
a pid which is non existing. so it should not be a reason for lsof to go in
sleep mode.
So I want to know that, is there any limitation / bug inside
the lsof for which it never come out from its call, or how lsof behaves if we
call it for a pid which was existing at the time of call but gets killed/go out
of scope/not existed while lsof is in processing (before come out with output).
Whether this situation is handled by lsof? if so then in
which case lsof can hangs/sleep and how to handle this situation. Or is their
any problem with popen?
Thanks in Advance .......
Harry