0

I am writing a cross-platform program which requires simple information on the running program: process name, process id, thread id.

The process id and thread id are simple to get on each platform, using pre-processor directives should do it.

But for the process name, I looked over the internet and I didnt find anything easy and a bit cross-platform which is not that surprising. Since I am writting a library which must be extremely simple to use, I don't have access to argv[0] which is exactly what I want.

I would like to know if someone had an easy way to do it ? This feature is not implemented in the official boost version.. unfortunately :(

Rippalka
  • 380
  • 6
  • 16

2 Answers2

2

Well, I doubt you will find a nice cross-platform solution.
Most likely you will end up having some platform specific code within #ifdef's.

Linux standard way is looking into /proc and parsing the results.
Windows way is using it's sick API.

Community
  • 1
  • 1
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
2

To supplement @Andrejs Cainikovs' answer, the Windows solution is a simple call to GetModuleFileName(NULL, charBuffer, elementCount):

tenfour
  • 36,141
  • 15
  • 83
  • 142