File: //proc/self/root/scripts.20110531.215904.25158/simpleps
#!/usr/bin/perl
# cpanel - simpleps Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::Encoder::Tiny ();
my $html = 0;
if ( $ARGV[0] =~ /html/i ) { $html = 1; }
if ( !$html ) {
print <<EOM;
Pid Name Exe Cwd
--------------------------------------------------------------------------------
EOM
format STDOUT =
@<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<
$proc, $name, $exe, $cwd
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cmd
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cmd
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cmd
--------------------------------------------------------------------------------
.
}
opendir( PROC, "/proc" );
@PIDS = readdir(PROC);
closedir(PROC);
foreach $proc (@PIDS) {
if ( $proc =~ /^\d*$/ ) {
open( PROCC, "/proc/$proc/cmdline" );
chomp( $cmd = <PROCC> );
close(PROCC);
open( PROCC, "/proc/$proc/stat" );
chomp( $procps = <PROCC> );
close(PROCC);
( undef, $name, undef ) = split( /\s/, $procps );
if ( -e "/proc/$proc/exe" ) {
$exe = readlink("/proc/$proc/exe");
}
else {
$exe = readlink("/proc/$proc/file");
}
$cwd = readlink("/proc/$proc/cwd");
if ( !$html ) {
write;
}
else {
$cmd =~ s/\0/ /g;
print "<tr><td>$proc</td><td>" . Cpanel::Encoder::Tiny::safe_html_encode_str($name) . "</td><td>" . Cpanel::Encoder::Tiny::safe_html_encode_str($exe) . "</td><td>" . Cpanel::Encoder::Tiny::safe_html_encode_str($cwd) . "</td><td>" . Cpanel::Encoder::Tiny::safe_html_encode_str($cmd) . "</td></tr>";
}
}
}