File: zombies

package info (click to toggle)
hobbit-plugins 20100527
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 196 kB
  • ctags: 32
  • sloc: perl: 1,080; makefile: 49; sh: 43
file content (28 lines) | stat: -rwxr-xr-x 405 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl -w

use strict;

chdir ("/proc");

my $zombies = 0;

foreach my $pid (glob ("[1-9]*")) {
	open F, "$pid/status" or next;
	while (<F>) {
		if (/^State:\s+Z/) {
			my $mtime = (stat ($pid))[9];
			last if not defined $mtime or time - $mtime < 60;
			system "ps u $pid";
			$zombies++;
			last;
		}
	}
	close F;
}

if ($zombies) {
	exit 1;
} else {
	print "No zombie processes\n";
	exit 0;
}