added monitor function which will terminate a program after a specified amount of time