473,769 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a win32 process running using the pid.

Guy
Hi, I created a function, which seems to work, quite well, it tells me
if a process is running in widows using the pid number (I'm aware that
the pid number in widows is not called a pid and this is really a unix
thing but what the hell). The function keeps crashing (I've included
the crash but I don't think it will do any good.), only sometimes,
most of the time it works fine and I don't know why, Could any body
suggest anything, maybe someone has a stable function that can do the
below :

CRASH
======

Traceback (most recent call last):
File "E:\MW\MAINLINE \Makefile\Build \PCBuild.py", line 607, in ?
PCBuild_Support .MakefileBuild( Makefile_Module s_lst,Flavour_l st,BuildSetUp,E nviroment)
File "E:\MW\MAINLINE \Makefile\Build \PCBuild_Suppor t.py", line 100,
in MakefileBuild
CreateBuildLogs (ModulesBeingBu ilt_lst)
File "E:\MW\MAINLINE \Makefile\Build \PCBuild_Suppor t.py", line 252,
in CreateBuildLogs
if(process.IsPr ocessRunning(Bu ild[4]._processId)==N ):
# Checks to see is process has ended. (The processID is the
pid number
and is obtained from the process class.(Your Flavorite Simon.))
File "E:\MW\MAINLINE \Makefile\Build \process.py", line 2450, in
IsProcessRunnin g
hcs.append(win3 2pdh.AddCounter (hq, path))
pywintypes.erro r: (-1, 'AddCounter', 'No error message is available')

FUNCTION
=========

# IsProcessRunnin g - Supply the process Id number and this function
will tell you if the process is running or not by returning Y and N.
def IsProcessRunnin g(pid):
if sys.platform.st artswith("win") :
object = "Process"
win32pdh.EnumOb jects(None, None, 0, 1)
items, instances = win32pdh.EnumOb jectItems(None, None,object,
win32pdh.PERF_D ETAIL_WIZARD)
# Need to track multiple instances of the same name.
instance_dict = {}
for instance in instances:
try:
instance_dict[instance] = instance_dict[instance] + 1
except KeyError:
instance_dict[instance] = 0
# Bit of a hack to get useful info.
items = ["ID Process"] + items[:5]
for instance, max_instances in instance_dict.i tems():
for inum in xrange(max_inst ances+1):
try:
hq = win32pdh.OpenQu ery()
hcs = []
for item in items:
path = win32pdh.MakeCo unterPath(
(None,object,in stance, None, inum, item) )
hcs.append(win3 2pdh.AddCounter (hq, path))
win32pdh.Collec tQueryData(hq)
type, val =
win32pdh.GetFor mattedCounterVa lue(hcs[0],win32pdh.PDH_F MT_LONG)
except:
val=0
if (val == pid):
return Y
win32pdh.Remove Counter(hcs[0])
win32pdh.CloseQ uery(hq)
return N
else:
return N

TIA
TTFN
Guy
Jul 18 '05 #1
0 2002

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1490
by: Tom Brown | last post by:
Hi, I created a win32 service for XPPro called N4010ATestService.py (see below). The service runs as a particular user with administrative rights. It starts a thread that creates a simple socket server (N4010ASocketServer.py -- also below) that just waits for 20 character string. When I run the socket server by itself the test client can connect to the server and send a 20 character string just fine. When I run the service, the server...
4
8466
by: Scaramouche | last post by:
is there an equivalent to unixs' ps command in perl? i was writing some win32 scripts and i needed a listing of specific processes. i could perhaps grep through a list of running processes but how can i attain that through perl? thanks
2
4995
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4. forkme.pl calls the process creation script (createme.pl) 5. createme.pl creates my notepad.exe process, but no window shows up on my PC. The result on my web browser is:
0
5140
by: rtm | last post by:
I am interested in running a process with a timeout. Also I'm interested in analyzing the output of this process. Under Unix, the solution is described clearly in the Perl Cookbook "16.10: Communicating between related processes" and 16.24 "Timing out an Operation". Enclosed below is an example showing what I want to do under Unix. I need to do this under Windows XP. As others have pointed out "alarm" works under 5.8+ and fork...
1
3570
by: Java and Swing | last post by:
i need to get information about the processes running on a windows pc (98, 2k, xp) i can get the pid's using, win32process.EnumProcesses()...and I can get a handle on a process using an id..such as handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, 0, pids) ...but how can i get the name of the process, path to process, etc. I
15
11788
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
5
3477
by: Henaro | last post by:
Hello~ I am having trouble setting environment variables in C++ on win32. The code that is not working is: char prxy; char pf_cmd1 = "set http_proxy="; ....
0
2442
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform some action. The java call looks like this: Win32::SetChildShowWindow(0); Win32::Process::Create(
3
4105
by: somuchh8 | last post by:
Hi, I'm having a lot of trouble with the Win32::Spawn module in perl. Here is my situation, I have a Win32::Spawn call which looks like this: my $success = undef; my $cmdline = EBDTools::os_path("${nh_home}/web/aview/modules/svcrsp-ng/saSync.pl"); $success = Win32::Spawn($^X, "${^X} $cmdline ${optfile}", $pid); if (! $success) { my $lasterr = Win32::GetLastError(); return_configerror("Failed to create commit / sync process...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.