473,320 Members | 1,948 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,320 software developers and data experts.

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_Modules_lst ,Flavour_lst,BuildSetUp,Enviroment)
File "E:\MW\MAINLINE\Makefile\Build\PCBuild_Support.py" , line 100,
in MakefileBuild
CreateBuildLogs(ModulesBeingBuilt_lst)
File "E:\MW\MAINLINE\Makefile\Build\PCBuild_Support.py" , line 252,
in CreateBuildLogs
if(process.IsProcessRunning(Build[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
IsProcessRunning
hcs.append(win32pdh.AddCounter(hq, path))
pywintypes.error: (-1, 'AddCounter', 'No error message is available')

FUNCTION
=========

# IsProcessRunning - Supply the process Id number and this function
will tell you if the process is running or not by returning Y and N.
def IsProcessRunning(pid):
if sys.platform.startswith("win"):
object = "Process"
win32pdh.EnumObjects(None, None, 0, 1)
items, instances = win32pdh.EnumObjectItems(None,None,object,
win32pdh.PERF_DETAIL_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.items():
for inum in xrange(max_instances+1):
try:
hq = win32pdh.OpenQuery()
hcs = []
for item in items:
path = win32pdh.MakeCounterPath(
(None,object,instance, None, inum, item) )
hcs.append(win32pdh.AddCounter(hq, path))
win32pdh.CollectQueryData(hq)
type, val =
win32pdh.GetFormattedCounterValue(hcs[0],win32pdh.PDH_FMT_LONG)
except:
val=0
if (val == pid):
return Y
win32pdh.RemoveCounter(hcs[0])
win32pdh.CloseQuery(hq)
return N
else:
return N

TIA
TTFN
Guy
Jul 18 '05 #1
0 1984

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

Similar topics

0
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...
4
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...
2
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....
0
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: ...
1
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...
15
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...
5
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
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...
3
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 =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.