Process monitoring script
Don't write custom scripts for common sysadmin tasks. Using the proper tools will get the job done better, and the solution will be more maintainable — especially by any colleagues you might have.

Using monit, for example, this would just be a matter of writing a simple configuration file.

set logfile /root/process_monitor.log
check process myproc with pidfile /tmp/pidfile.pid
    restart program = "shutdown -r -t 10"  # draconian!
    every "15 4 * * *"
    if memory &gt; 20 MB then restart myproc