How to get the process name for a given pid in Solaris?

We have huge log files where the process pid is one of the informations given with a log entry.

Does anybody know an api function to retrieve the process names (or better the start command process + arguments) ?

TIA
Alex
LVL 39
itsmeandnobodyelseAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

itsmeandnobodyelseAuthor Commented:
I could do it by

  char strpid[] = "11111";
  char stmt[256] = { '\0' };
  sprintf(stmt, "ps -f -p %s >ps.out", strpid);
  system(stmt);

and parse the ps.out after that.

But I would prefer an api.

0
jkrCommented:
Is that a newer version of Solaris? If so, you could read '/proc/<pid>/psinfo' from 'psinfo.pr_psargs' as demonstrated in http://nagiosplug.svn.sourceforge.net/viewvc/nagiosplug/nagiosplug/trunk/plugins-root/pst3.c?view=markup&pathrev=2016 (man, that was not easy to find an example online...)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
>>you could read '/proc/<pid>/psinfo' from 'psinfo.pr_psargs'

Sorry, make that "you could read '/proc/<pid>/psinfo' and get the name from 'psinfo.pr_psargs'"
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

itsmeandnobodyelseAuthor Commented:
>>>> man, that was not easy to find an example online...

;-)

>>>>  This executable works by reading process address structures, so needs to be executed as root

That could be a problem cause the logfiles were written by non-root processes.

>>>> Is that a newer version of Solaris?

It is Solaris 9.

0
jkrCommented:
OK, Solaris 9 should definitely be fine: http://en.wikipedia.org/wiki/Procfs#Solaris
0
itsmeandnobodyelseAuthor Commented:
I found a link at

http://www.sunmanagers.org/pipermail/summaries/2002-May/001674.html

which does similar, i. e.

- open /proc/<pid> what gives file descriptor fd of <pid> folder
 
- iocntl on the fd what fills prpsinfo structure  (from old_procfs.h).

- Then prpsinfo has member pr_fname what is the process name

(actually it is not really simple)

But main drawback also seems to be that we would need more access rights to read that information at runtime as we have today.


0
itsmeandnobodyelseAuthor Commented:
What do you think of catching the output of

   pfiles <pid>

with popen ?

0
jkrCommented:
Might be an option, but the question is whether the exectuable image is listed as an opened file (can't test it, no Solaris here)...
0
jdarwinCommented:
I think when a process is run and re-run, each time a different PID is asigned to it, except for process like init.

If so, then would it be possible to relate an old PID with a process in your log file, unless the process name is also logged in your log files.
0
itsmeandnobodyelseAuthor Commented:
>>>> .... unless the process name is also logged in your log files.
Yes, that is the goal. We want to have logfile entries with timestamp, pid, processname, severity, errorcode, errortext (free).

0
itsmeandnobodyelseAuthor Commented:
We probably use the solution to redirect the output of ps to a file. Though it is about 150 processes which could write to the logfiles, the pid's mostly are the same (the processes do not restart but keep running permanently). So the overhead for retrieving the processname once for a new pid is acceptable.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.