Rippalka
Rippalka

Reputation: 380

C++ - Process infos

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 :(

Upvotes: 0

Views: 511

Answers (2)

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28474

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.

Upvotes: 2

tenfour
tenfour

Reputation: 36896

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

Upvotes: 2

Related Questions