Working with Erlang a bit more recently, and also
with the very handy heart command line parameter.
(I strongly recommend this tutorial as an introduction to heart.)
The heart parameter allows you to specify a command
to be run if your Erlang process crashes:
If myscript crashes, it will automatically be restarted,
which is undeniably handy. However, it is possible to end up
with heart processes which are monitoring a non-existant Erlang
process. When the monitored Erlang process dies, then a new Erlang
process is spawned, along with a new heart process. Sometimes
the old heart process isn't correctly disposed of if
your application is crashing frequently (for example you try to
run invalid code with heart monitoring it), you can end up with a number
of unwanted heart processes lingering around aimlessly.
This short Perl script eliminates all heart processes which
are monitoring a non-existant process. It is safe to run with
multiple heart processes1, and can be either run manually or
added as a periodic cronjob.
If you ran this script at the exact moment a monitored process crashed,
it seems possible it would inappropriately terminate the new heart process
(a simply remedy would be to avoid terminating any heart processes that
are less than 5 seconds old).