Monika
Monika

Reputation:

Process ID and OS Information in C++

In python I can use os.getpid() and os.name() to get information about the Process ID and OS name. Is there something similar in C++? I tried GetProcessId() but was told that this is undeclared... I am using Cygwin under windows.

Thank you

Upvotes: 0

Views: 1343

Answers (3)

Judge Maygarden
Judge Maygarden

Reputation: 27583

To use GetProcessId you need to include Windows.h and link to Kernel32.lib. See Process and Thread Functions for more information.

I use MSYS/mingw instead of cygwin. So, you may need the w32api package installed.

Upvotes: 1

Don
Don

Reputation:

I recommend Hart's book "Win32 System Programming". Great discussion about how to manage processes, memory, files etc in Kernel32, if you're just starting to look at Windows programming. You can also get a free version of Visual Studio (http://www.microsoft.com/express/).

Upvotes: 0

anon
anon

Reputation:

Standard C++ has no such functionality. You need to use OS specific features to get this. In your case, you need to look up POSIX/UNIX functions such as getpid().

Note that if you actually do want to call the Windows functions to get process ID etc, you should be using a C++ environment like MinGW, which allows you to build native Windows applications, rather than Cygwin, which is more aimed at porting POSIX apps to Windows.

Upvotes: 3

Related Questions