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
What Does % Do to Strings in Python
Why Is Variable1 += Variable2 Much Faster Than Variable1 = Variable1 + Variable2
What Is a "Good" Palette for Divergent Colors in R? (Or: Can Viridis and Magma Be Combined Together)
If Monkey Patching Is Permitted in Both Ruby and Python, Why Is It More Controversial in Ruby
How to Redirect Stdout to Both File and Console with Scripting
A Mutable Type Inside an Immutable Container
Open File in a Relative Location in Python
How to Get Value Counts for Multiple Columns at Once in Pandas Dataframe
Pandas New Column from Groupby Averages
How to Generate an HTML Directory List Using Python
Is There a Static Analysis Tool for Python, Ruby, SQL, Cobol, Perl, and Pl/Sql
Looking for Recommendation on How to Convert PDF into Structured Format
How to Access the Request Object or Any Other Variable in a Form's Clean() Method