Runaway "Perl" Process

Discussion in 'macOS' started by supafly1703, Feb 21, 2006.

  1. supafly1703 macrumors regular

    Joined:
    Jul 11, 2004
    #1
    Hey guys, I have this process called "Perl" that periodically runs and starts monopolizing my cpu. I force quit it everytime and there is no real effect on the system (i.e., apps don't stop working or anything). Any solutions?

    Running Tiger 10.4.5 on a 1.67 GHz Powerbook.
     
  2. mwpeters8182 macrumors 6502

    Joined:
    Apr 16, 2003
    Location:
    Boston, MA
    #2
    most likely you're running some sort of program that uses a perl script to do something, and something's one awry. Can you pinpoint when it starts up?
     
  3. bankshot macrumors 65816

    bankshot

    Joined:
    Jan 23, 2003
    Location:
    Southern California
    #3
    When you notice it running next, open up Terminal and execute this command:

    Code:
    ps uaxww | grep -i perl
    This will tell you a bit more about what it's actually running. In case you (or someone else) didn't know, perl is a very common scripting language on unix, and a perl process could doing any one of about a billion different things. It all depends on what script it's running. So the first step is to determine the script by looking at the process data above.
     
  4. supafly1703 thread starter macrumors regular

    Joined:
    Jul 11, 2004
    #4
    Thanks a lot, will do that next time I see it pop up...
     
  5. supafly1703 thread starter macrumors regular

    Joined:
    Jul 11, 2004
    #5
    What I get when I type that

    adamjone 3422 0.7 0.2 28748 2636 ?? Ss 8:14PM 0:21.08 /usr/bin/perl -e %dirs = ("/Applications", 1,"/Users/adamjones/Applications/", 1);%sp_hash = ();$sp_hash{"Azureus"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist);^I^I$_ = (read_prop($plist, $cnt, "CFBundleGetInfoString"));^I^Is/^Azureus //;^I^Ireturn $_;^I};$sp_hash{"Gizmo Project"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist); ^I^Ireturn (read_prop($plist, $cnt, "CFBundleShortVersionString")).(".").(read_prop($plist, $cnt, "CFBundleVersion"));^I};$sp_hash{"OmniWeb"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist);^I^Ireturn (read_prop($plist, $cnt, "CFBundleShortVersionString"));^I};$sp_hash{"RealPlayer"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist); ^I^Ireturn (read_prop($plist, $cnt, "CFBundleShortVersionString")).(".").(read_prop($plist, $cnt, "CFBundleVersion"));^I};$sp_hash{"sixtyforce"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist);^I^Ireturn (read_prop($plist, $cnt, "CFBundleShortVersionString"));^I};$sp_hash{"TemperatureMonitor"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist);^I^Ireturn (read_prop($plist, $cnt, "CFBundleShortVersionString"));^I};$sp_hash{"TeXShop"} = ^Isub { my($plist) = $_[0]."Info";^I^Imy($cnt) = read_plist($plist);^I^Ireturn (read_prop($plist, $cnt, "CFBundleVersion"));^I};sub recurse_directory {^Ireturn () if (@_ == ());^Imy($dir) = @_;^Imy(@dirs) = ();^Iif (opendir DIR, $dir) {^I^I@dirs = readdir DIR;^I^Iclose DIR;^I^I@dirs = map { $dir . "/" . $_ } @dirs;^I^I@dirs = grep { (-d $_ && -r $_ && !/((\/\.\.)|(\/\.)|(\.wdgt)|(\.app)|(\.bundle)|(\.framework)|(\.component)|(\.prefPane))$/) } @dirs;^I}^Ipush @dirs, map { recurse_directory($_) } @dirs; ^Ireturn @dirs;}sub read_plist {^Imy($content) = "";^Iif (open(PLIST, ($_[0].".plist"))) {^I^I$content = join "", (<PLIST>);^I^Iclose FILE;^I}^Ireturn $content;}sub read_prop {^Imy($path, $content, $prop) = @_;^Iif ($content =~ ^I^I/\<\s*key\s*\>\s*$prop\s*\<\/\s*key\s*\>\s*\n?\s*\<\s*string\s*\>\s*(.*?)\s*\<\/\s*string\s*\>/i) {^I^Ireturn $1;^I}^I$path = quotemeta($path);^I$prop = quotemeta($prop);^Imy(@l) = readpipe "/usr/bin/defaults read $path $prop 2>/dev/null";^I($#l != 0) and return "";^Imy($val) = $l[0];^Ichop $val;^I$val =~ s/^.*does not exist$//g;^I$val =~ s/\t/ /g;^Ireturn $val;}sub get_str {^Imy($name, $ver) = ("", "");^Iforeach $plist ("Info", "Info-macos", "version") {^I^Iforeach $subdir ("/Contents/", "/Resources/") {^I^I^Imy($path) = $dir . "/" . $_ . $subdir . $plist;^I^I^Iif (-r $path.".plist") {^I^I^I^Imy($content) = read_plist($path);^I^I^I^Iif ($plist eq "Info" || $plist eq "Info-macos") {^I^I^I^I^I$name = read_prop($path, $content, "CFBundleDisplayName");^I^I^I^I^Iif ($name eq "") {^I^I^I^I^I^I$name = read_prop($path, $content, "CFBundleName");^I^I^I^I^I}^I^I^I^I^Iif ($name eq "") {^I^I^I^I^I^Imy($dirname) = $_;^I^I^I^I^I^I$dirname =~ s/\.(app|framework|component|prefPane)$//g; ^I^I^I^I^I^I$name = $dirname; ^I^I^I^I^I} ^I^I^I^I}^I^I^I^Iif (exists($sp_hash{$name})) {^I^I^I^I^Imy($the_dir) = $dir . "/" . $_ . $subdir . "/"; ^I^I^I^I^Imy($func) = $sp_hash{$name}; ^I^I^I^I^I$ver = &$func($the_dir);^I^I^I^I^Igoto CUSTOM_VER;^I^I^I^I} else {^I^I^I^I^Iforeach $prop ("CFBundleVersion", "CFBundleShortVersionString") {^I^I^I^I^I^Imy($ver_candidate) = read_prop($path, $content, $prop);^I^I^I^I^I^I$ver = $ver_candidate if ($ver lt $ver_candidate && ($ver eq "" || $ver_candidate =~ /\./));^I^I^I^I^I}^I^I^I^I}^I^I^I}^I^I}^I}CUSTOM_VER:^Iif ($name ne "") {^I^Iif (/\.framework$/) { ^I^I^I$name = $name . " Framework"; ^I^I} elsif (/\.component$/) {^I^I^I$name = $name . " Component"; ^I^I} elsif (/\.prefPane$/) {^I^I^I$name = $name . " PrefPane"; ^I^I}^I}^I$name ne "" && $ver ne "" && print STDERR "$name\t$ver\n";}$osascript = ""; sub compileOSA {^Iif ($osascript eq "") {^I^Ido {^I^I^I$osascript = "/tmp/".(rand * 1000000).".scpt";^I^I} while (-e $osascript); ^I^Imy(@res) = readpipe "/usr/bin/osacompile -o $osascript ^I^I^I-e \"on run argv\" ^I^I^I-e \"tell application \\\"Finder\\\" to get package folder of ^I^I^I^I(info for the file (get POSIX file (item 1 of argv) as string))\" ^I^I^I-e \"end run\"";^I}}sub isPackage {^Imy($dir) = shift;^I&compileOSA;^Imy(@res) = readpipe "/usr/bin/osascript $osascript \"$dir\"";^Ireturn $res[0] eq "true\n";}@the_dirs = keys %dirs;foreach $dir (keys %dirs) {^Iif ($dirs{$dir}) {^I^Ipush @the_dirs, recurse_directory($dir);^I}}foreach $dir (@the_dirs) {^Iprint "$dir\n";^Iif (-r $dir && (-d $dir || -l $dir)) {^I^Iif (opendir DIR, $dir) { ^I^I^I@widgets = grep { $_ !~ /^\./ && ($_ =~ /\.(app|framework|component|prefPane)\/*$/ || ^I^I^I^I($_ !~ /\.(bundle|nib|kext|plugin|smrd)\/*$/ && ^I^I^I^I(-r "$dir/$_/Contents/Info.plist" || -r "$dir/$_/Contents/Info-macos.plist" || ^I^I^I^I -r "$dir/$_/Resources/Info.plist" || -r "$dir/$_/Resources/Info-macos.plist") && ^I^I^I^IisPackage("$dir/$_")))} (readdir DIR);^I^I^Iclose DIR;^I^I^I(scalar @widgets > 0) and map get_str, @widgets;^I^I^Iprint "OK\n";^I^I}^I}}if ($osascript ne "") {^Isystem "rm -f $osascript > /dev/null 2>&1;";}
    adamjone 4401 0.0 0.0 18060 260 p1 R+ 8:18PM 0:00.00 grep -i perl





    What does it mean? (And I don't have Azureus open!)
     
  6. bankshot macrumors 65816

    bankshot

    Joined:
    Jan 23, 2003
    Location:
    Southern California
    #6
    Wow, that's really odd. Whatever's running that has put the entire script on the command line. At least that made it easy to look through and figure out what it's doing. ;)

    Basically, the script looks through your entire Applications directory and spits out the version numbers of all the apps it can find. I don't know why it's doing this or how that information is being used. Or what program is running it in the first place. That's where you have to trace back up the process tree to find what called it.

    Next time it happens, do this instead:
    Code:
    ps laxww | grep -i perl
    Look for a similar big huge line, but this time look at the third number from the left. That tells you the parent process id. The second number is perl's process id. What you want to do is look for the parent process id (third number) to find out what program called it. So if the number is 12345, you'd do:
    Code:
    ps laxww | grep 12345
    This time you'd look for the line with 12345 as the second number. That's the parent process, and the third number in that line will be its parent process. You can keep doing this to trace back up until you find something you recognize.

    For example, I want to trace what programs called the weather widget. First, I do:
    Code:
    ps laxww|grep -i weather
      405  4397  3396   0  63  0   127340   7628 -      S     ??    0:01.62 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Weather.wdgt/ 4855 41a1abb0f66011f5 f
    
    From this, I see that process id 4397 is the weather widget, and it has parent process 3396. I look for 3396:
    Code:
    ps laxww | grep 3396
      405  3396    71   0  46  0   134624  10536 -      S     ??    0:07.83 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock -psn_0_7471105
      405  4395  3396   0  63  0   133152   4908 -      S     ??    0:00.76 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Google.wdgt/ 4853 41a30abbbb059b1b f
      405  4396  3396   0  63  0   133564   6700 -      S     ??    0:01.21 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Dictionary.wdgt/ 4854 41a04b8e2e89e7b8 f
      405  4397  3396   0  63  0   127340   7628 -      S     ??    0:01.62 /System/Library/CoreServices/Dock.app/Contents/Resources/DashboardClient.app/Contents/MacOS/DashboardClient /Library/Widgets/Weather.wdgt/ 4855 41a1abb0f66011f5 f
    
    Ok, I see a few other widgets have the same parent process id, but the main line I'm interested in is the first one, with 3396 as the process id. Looks like Dock is running the widgets. It has a parent process id of 71, so what's that?
    Code:
    ps laxww | grep 71
       88    71     1   0  63  0   210516  70172 -      Ss    ??   63:59.82 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer -daemon
      405   225    71   0  63  0   143100   9616 -      S     ??   32:03.87 /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer -psn_0_655361
    
    ... (and a whole bunch of other stuff) ...
    Looks like WindowServer runs Dock, plus a whole bunch of other stuff that I cut out. WindowServer was started by process id 1, which is launchd. Using this method, hopefully you can figure out what is running that script. I've never seen it, so I have no idea. :confused:
     
  7. supafly1703 thread starter macrumors regular

    Joined:
    Jul 11, 2004
    #7
    Awesome!

    Using the aforementioned method I determined the problem to be the App Update widget, which hogs the computer when checking for app updates. Thanks again!
     

Share This Page