How to get PID of a process from a C program

S

Srini

Hi

Could someone please let me know how to get a PID of a process from a
C Program on Windows platform.

e.g
I have a C program executable called myprog.exe and there could be
several instances of this program running. I would like to know the
PID(process id) of a given instance of myprog.exe.

I guess I can call the system() function and execute the following DOS
command.
tasklist /fi "IMAGENAME eq myprog.exe" /nh /fo "TABLE"

But this will give me a list of all the instances of myprog.exe

My questions is how can i figureout the PID of the instance I am
running from within myprog.c?

Thanks a lot for your time in advance.
Srini
 
K

Kenneth Brody

Srini said:
Hi

Could someone please let me know how to get a PID of a process from a
C Program on Windows platform.
[...]

Well, in "C" you probably can't. In your particular dialect of C, there
may be a way. Why not check the documentation for your particular flavor
of C? To get the PID, you may consider looking for a function that may
be called something like "getpid" perhaps.

--

+---------+----------------------------------+-----------------------------+
| Kenneth | kenbrody at spamcop.net | "The opinions expressed |
| J. | http://www.hvcomputer.com | herein are not necessarily |
| Brody | http://www.fptech.com | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+
 
M

Mark A. Odell

(e-mail address removed) (Srini) wrote in

Could someone please let me know how to get a PID of a process from a
C Program on Windows platform.

By asking in a win32 programming newsgroup? This is not a C language
question.
 
J

Jack Klein

Hi

Could someone please let me know how to get a PID of a process from a

Basically, you compute the sum of at least three terms:

Kp * e(n)
Ki * (e(n)+e(n-1)+e(n-2)...+e(1)+e(0))
Kd * (e(n)-e(n-1)

Customizations abound.
C Program on Windows platform.

Oh, that kind of PID. No way to do that in standard C, whereas it is
quite possible to do the computations for a Proportional, Integral,
Derivative control loop in standard C.

The Windows newsgroups are that'a'way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top