Perl script running infinitely - how to debug what happened?
Try to follow these steps: - find the process pid of the shell, you may use a command like:
ps -ef | grep <your_script_name>
Let's set this pid in the shell variable $PID. Find all the child processes of this $PID by run the command:
ps --ppid $PID
You might find one or more (if for example it's stuck in a pipelined series of commands). Repeat this command couple of times. If it doesn't change this means the script is stuck in certain command. In this case, you may attach trace command to the running child process:
sudo strace -p $PID
This will show you what is being executed, either indefinite loop (like reading from a pipe), or waiting on some event that never happens.
In case you find ps --ppid $PID
changes, this indicates that your script is advancing but it's stuck somewhere, e.g. local loop in the script. From the changing commands, it can give you a hint where in the script it's looping.
Finally, a very simple method to debug a perl is to use perl debugger:
perl -d script.pl
More: 1, 2, 3, 4, 5
For the next runs of your script you can try out the package Devel::Trace.
From description: "This module will print a message to standard error just before each line is executed."
Run either with
perl -d:Trace program
or use in your script with
import Devel::Trace 'trace';
trace 'on'; # Enable
trace 'off'; # Disable