Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Kill process program??

by Chad_MacArthur (Initiate)
on Apr 28, 2004 at 14:05 UTC ( [id://348828]=perlquestion: print w/replies, xml ) Need Help??

Chad_MacArthur has asked for the wisdom of the Perl Monks concerning the following question:

G'day guys

I was wondering what kind of UNIX system commands I would use to write a program that will just show me details on current running programs + status

example process id, user, process, state, cpu, memory used, virtual memory size, resident set size and major page faults if any.

Thank mate for the Help
ANy help would be Great
Chad

edit (broquaint): added some minimal formatting

Replies are listed 'Best First'.
Re: Kill process program??
by atcroft (Abbot) on Apr 28, 2004 at 14:52 UTC

    Between this and your other writeup today, it seems as if you are looking at writing administrative scripts. May I suggest that you find and browse the book Perl for System Administration, by David N. Blank-Edelman, published by O'Reilly and Associates (reviewed here). I suspect that it may cover/introduce several of the items you appear to be interested in (including process control, which appears in chapter 4).

    Hope that helps...

Re: Kill process program??
by bronto (Priest) on Apr 28, 2004 at 14:14 UTC
    I was wondering what kind of system commands I would use to write a program that will just show me details on current running programs + status example process id, user, process, state, cpu, memory used, virtual memory size, resident set size and major page faults if any

    Unfortunately, you forgot to tell us what is the system you are working on...

    Update: read this for some suggestions

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz
Re: Kill process program??
by Theo (Priest) on Apr 28, 2004 at 14:12 UTC
    What have you tried so far, Chad_MacArthur? Any code or even ideas on what to do? The Monastery is a great place for getting help, but we usually like to see some effort first. :)

    -Theo-
    (so many nodes and so little time ... )

Re: Kill process program??
by AcidHawk (Vicar) on Apr 29, 2004 at 07:00 UTC
    Check out Win32 Perl Scripting: The Administrator's Handbook by Roth. There are loads of Admin script in there.

    Also check his script repository for more admin scripts.

    Update: I include a simple script that takes a command line parameter and searches for that in the process list and kills all instances found.. to test simply launch many notepad.exe processes.. then run the following script I.e. pkill.pl notepad

    #! /usr/bin/perl use strict; use warnings; use Win32; use Win32::API; use Win32::Process; use Win32::OLE qw( in ); #Identify the Process that have been left +to kill use Win32::OLE::Variant; #Identify the Process that have been left +to kill my $app = $ARGV[0]; if ($app) { my $rc = 1; my $srv = "\\\\" . $ENV{'COMPUTERNAME'}; my $CLASS = "winmgmts:{impersonationLevel=impersonate}$srv\\Root\\ +cimv2"; my $WMI = Win32::OLE->GetObject( $CLASS ) || die; foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in( $WMI +->InstancesOf( "Win32_Process" ) ) ) { my $regex1 = "($app)"; if ($Proc->{Name} =~ /$regex1/i) { print "INFORMATION - About to kill $Proc->{ProcessID} for +$app\n"; unless (Win32::Process::KillProcess($Proc->{ProcessID}, 0) +) { print "Could not kill $Proc->{ProcessID} for $app\n"; } } } } else { print "$0 <app name>\n"; print "<app name> = name and extension or (part therof I.e. note f +or notepad) of process to kill\n"; }
    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: Kill process program??
by OzzyOsbourne (Chaplain) on Apr 28, 2004 at 18:11 UTC
    I have perl scripts that call Sysinternal's PSTools package to do remote process views/kills etc. You could also delve into Win32::Process, but it's not as effective. But then, this is all win-centric.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://348828]
Approved by bronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found