1

Possible Duplicate:
How to get Process Name in C++

I am looking for a way to to get the process name from the PID?

I need to translate process id (PID) to process name

any idea?

Community
  • 1
  • 1
MoShe
  • 6,197
  • 17
  • 51
  • 77
  • 1
    What platform (Linux or Windows or...) are you on ? – Yahia Oct 16 '11 at 14:01
  • You should add the tag posix or windows, pid is not in the c++ standard. –  Oct 16 '11 at 14:01
  • There is a strong argument that the PID is the process's name. The information you are after is the name of the executable that was run to create the process. That said, your question is clear enough, though thlanguage used is somewhat imprecise. – Jonathan Leffler Oct 16 '11 at 14:20

2 Answers2

3

it depends on the used platform like Yahia mentioned in his comment.

on linux: you can get the command-line by reading that file: /proc/[PID]/cmdline

on windows: I've found this: get process name from process id (win32)

Community
  • 1
  • 1
thomas
  • 5,637
  • 2
  • 24
  • 35
1

On Windows you can open the process using OpenProcess in order to get a handle to the process. After that you can get the process name with GetProcessImageFileName and close the handle (CloseHandle).

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33