get process name from pid - getcommandline

All,

I have a requirement to get the process name of the newly execv'd process.

After getting the complete process name, I need to carry out further operations on that.

Problem so far is how do I retrieve the name of the process ?

There is an API in windows called GetCommandLine. I need something similiar to that in Linux.

I tried this forum and a whole lot of other google results. Nothing helped.

The best I have come up is Linux maintains a struct for each process, and a struct member supoosedly hold the process name. But I cant figure out which/what struct that is.

Any pointers will be appreciated.

Thanks,
Vino

There is not any general way to do this unix. Each OS has different ways to handle it and some are very hard. You mention Linux though. With Linux, the info is in the /proc filesystem. To get the command line for process id 9999, read the file "/proc/9999/cmdline".

Perfect. This is what I was looking for !!

Thanks Perderabo !

Vino