By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

How to get PID of a process from a C program

P: n/a
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
Nov 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
sa***@hotmail.com (Srini) wrote in
news:18*************************@posting.google.co m:
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.

--
- Mark ->
--
Nov 14 '05 #2

P: n/a
Srini wrote:

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." |
+---------+----------------------------------+-----------------------------+
Nov 14 '05 #3

P: n/a
On 9 Jan 2004 09:48:57 -0800, sa***@hotmail.com (Srini) wrote in
comp.lang.c:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.