Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Zombie Hunter (666th post)

by jeffa (Chancellor)
on Jan 19, 2002 at 00:46 UTC ( #139947=CUFP: print w/ replies, xml ) Need Help??

I had to come up with something evil yet playful for my 666th post, this is it.

I wish i could have obfuscated it, but alas. And yes, this for *NIX systems only (sorry Darwin users, deprecated confirmed that you are out to). The processes themselves are not really zombie processes - that would be...too evil. >:)

WARNING: don't run this if you don't know how to kill processes! (and don't forget about 'killall' and -9 for the occasional 'Super Zombie'!) ;)

#!/usr/bin/perl -lw use strict; # necromancer my $zombie,$|++,print $/; $SIG{TERM} = sub { hit $zombie; destroy $zombie and return unless $zombie->walks; print qq|"BRAINS!" (|,$zombie->health,' left)'; }; for (1..6) { next if fork; $zombie = raise Zombie; sleep 1 and regen $zombie while 666; } package Zombie; sub raise {print "$$ rises" and bless {hits=>int(rand 5)+2},shift} sub hit {shift->{hits}--} sub walks {shift->{hits} > 1} sub health {$_=shift->{hits};$_ > 1 ?"$_ hits":"$_ hit"} sub regen {shift->{hits}+=3 if int(rand 2)} sub destroy{print qq|"brainsss..." zombie destroyed| and exit}

P.S. deprecated tells me that some Unix systems do not have 'killall', 'pgrep', or 'pkill' handy. He recommends using this for such systems instead:

kill `ps Af | grep perl | grep -v grep | awk '{ print $2 }'`
"sometimes its ps -ef sometimes its ps -xawu and so on. solaris does have pgrep and pkill (but not before 2.6), and many of the BSD's (free open and net) will not have either so the awkkill is necessary."

Thanks deprecated! I named this script zombie.pl, so i would replace 'perl' in the line above with zombie.pl. Don't forget that you can add -9 to 'kill' in the line above as well, but that takes all the fun out! Happy Hunting! ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Comment on Zombie Hunter (666th post)
Select or Download Code
Re: Zombie Hunter (666th post)
by metadoktor (Hermit) on Jan 19, 2002 at 03:35 UTC
    raise Zombie;
    That's cute!

    metadoktor

    "The doktor is in."

Re: Zombie Hunter (666th post)
by Phaysis (Pilgrim) on Jan 21, 2002 at 05:22 UTC
    Yes!!! I love it! Hilarious! I haven't seen something akin to a shell game in years, not since my adventures on the school's Vax 9600/20e and its room full of VT102's (ah, the days of yore...).

    It was serendipitous that I also just learned about "killall" and its uses. Sure do need it with these zombie cron jobs.

    That completely rocks, Jeffa.

    -Shawn
    (Ph) Phaysis
    "If idle hands are the tools of the devil, are idol tools the hands of god?"

      Something my boyfriend told me about killall:
      Under some unix-like systems (i think it was on HP???) killall is different. It takes no arguments and kills all processes of the user.
        On this particular big box:HP-UX frank B.11.00 U 9000/800 75635 unlimited-user license
        Which as you see is HP-UX 11, killall is totally different that the linux killall. As we see from the manpage:
        NAME killall - kill all active processes SYNOPSIS /usr/sbin/killall [signal] DESCRIPTION killall is a procedure used by /usr/sbin/shutdown to kill all ac +tive processes not directly related to the shutdown procedure. killall is chiefly used to terminate all processes with open fil +es so that the mounted file systems are no longer busy and can be unmo +unted. killall sends the specified signal to all user processes in the system, with the following exceptions: the init process; all processes (including background processes) associated w +ith the terminal from which killall was invoked; any ps -ef process, if owned by root; any sed -e process, if owned by root; any shutdown process; any killall process; any /sbin/rc process. killall obtains its process information from ps, and therefore m +ay not be able to perfectly identify which processes to signal (see ps( +1)). If no signal is specified, a default of 9 (kill) is used. killall is invoked automatically by shutdown The use of shutdown + is recommended over using killall by itself (see shutdown(1M)). FILES /usr/sbin/shutdown SEE ALSO fuser(1M), kill(1), ps(1), shutdown(1M), signal(5). STANDARDS CONFORMANCE killall: SVID2, SVID3 Hewlett-Packard Company - 1 - HP-UX Release 11.00: Octobe +r 1997
        So, what it does is basically destroys all stubborn running processes still left during a system shutdown. Certainly not the same thing as a Linux killall, which really is just (as far as I can tell) a fancy signal sending multiplexer.

        On a marginally related note, be careful and stingy with your kill -9 (and killall's as well)... lest you find yourself recepient of merlyn's Useless use of kill award :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://139947]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-30 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls