473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to get PID of a process from a C program

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
3 16607
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
7
by: Samantha | last post by:
Hello , I am developping a program for Win98 plateform, and I am stucking with a problem, hope you can help me. I have a program running 2 process : - One process running the Xcopy.exe -...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
4
by: UJ | last post by:
Is the name of process always the name of executable that is running? I'm assuming a single process for a program. So in other words - if I want to check if a program is running, can I do a...
16
by: Caroline | last post by:
I am building a web application to gather user information then launch a process to calculate results. The process is a 3rd Party executable. I cannot get the process to start. Is there a...
4
by: Miro | last post by:
I'm using VB.Net 2003 I have code - it works great - to kill a process(s) if they are running. ---- Dim myProcesses() As Process 'Funny - withouth the () in the myProcesses it does not work...
2
by: JBudge | last post by:
I've created a program that will create zips and exes of all the product downloads on our website (mostly clipart and PowerPoint templates, around 6000 total), but the program slows down...
1
by: desivirus | last post by:
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin , $gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe psapi.h...
6
by: itsraghz | last post by:
Dear All, I have an issue with destroy() method of java.lang.Process class. All what I am trying to do is, controlling the execution of one program through another. Let's say, Program B has to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.