List Running Processes on 64-Bit Windows

List running processes on 64-bit Windows

There is another recipe on activestate that does a similar thing, but uses the Performance Data Helper library (PDH) instead.

I have tested this on my Windows 7 64bit machine and it works there - so presumably the same function will work on both 32bit and 64 bit windows.

You can find the recipe here: http://code.activestate.com/recipes/303339/

Another method is using WMI, there is an example here in Python using the wmi module:

http://timgolden.me.uk/python/wmi/cookbook.html

import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
print process.ProcessId, process.Name

Windows running processes list perl

As skp mentioned, the tasklist command can do it (tested on Windows XP).

Here is a small script that creates a hash of processes by PID:

use warnings;
use strict;

my @procs = `tasklist`;

#Find position of PID based on the ===== ====== line in the header
my $pid_pos;
if ($procs[2] =~ /^=+/)
{
$pid_pos = $+[0]+1;
}
else
{
die "Unexpected format!";
}

my %pids;
for (@procs[3 .. $#procs])
{
#Get process name and strip whitespace
my $name = substr $_,0,$pid_pos;
$name =~s/^\s+|\s+$//g;

#Get PID
if (substr($_,$pid_pos) =~ /^\s*(\d+)/)
{
$pids{$1} = $name;
}
}

use Data::Dumper;
print Dumper %pids;

Another approach that might be useful is Win32::Process::List. It gets the process list using core Windows C functions. It appears to work with old versions of Perl.

Check if a running process is 32 or 64 bit

On OS X, ps's flags value includes a bit that indicates 64-bit mode:

$ ps -oflags= [PID]
4004

From the ps man page:

 flags     The flags associated with the process as in the include file
<sys/proc.h>:

P_ADVLOCK 0x00001 Process may hold a POSIX
advisory lock
P_CONTROLT 0x00002 Has a controlling terminal
P_LP64 0x00004 Process is LP64
P_NOCLDSTOP 0x00008 No SIGCHLD when children stop
[etc...]

...so if the flags value's last digit is 4, 5, 6, 7, c, d, e, or f, it's running in LP64 (i.e. 64-bit) mode. In the above example, flags=4004, so the process listed is 64-bit.

how to check whether services is running on 32 or 64 bit mode

You can check the task manager, 32 bit processes have *32 appended to their name in the processes list.

How to know whether a process in windows is running or not in python

The page you linked uses os.popen()(official docs here)

In windows, you should use "tasklist" as arg for os.popen(), rather than "ps -Af"

e.g.

>>> import os
>>> tmp = os.popen("tasklist").read() # it would return a str type
>>> "python.exe" in tmp
True


Related Topics



Leave a reply



Submit