Perl script running infinitelly - how to debug what happen?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am running Perl script on Linux machine via cron job. However, from time to time (around 1% of all cases), the script stucks and run infinitelly. If I list processes, I can see its PID. However, I dont want to kill it right away, I would rather know what went wrong.
Is there a way, how to show what lines are being executed from the script? Something like step-by-step debugging of the script based on PID.
linux perl
add a comment |Â
up vote
1
down vote
favorite
I am running Perl script on Linux machine via cron job. However, from time to time (around 1% of all cases), the script stucks and run infinitelly. If I list processes, I can see its PID. However, I dont want to kill it right away, I would rather know what went wrong.
Is there a way, how to show what lines are being executed from the script? Something like step-by-step debugging of the script based on PID.
linux perl
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am running Perl script on Linux machine via cron job. However, from time to time (around 1% of all cases), the script stucks and run infinitelly. If I list processes, I can see its PID. However, I dont want to kill it right away, I would rather know what went wrong.
Is there a way, how to show what lines are being executed from the script? Something like step-by-step debugging of the script based on PID.
linux perl
I am running Perl script on Linux machine via cron job. However, from time to time (around 1% of all cases), the script stucks and run infinitelly. If I list processes, I can see its PID. However, I dont want to kill it right away, I would rather know what went wrong.
Is there a way, how to show what lines are being executed from the script? Something like step-by-step debugging of the script based on PID.
linux perl
linux perl
asked 5 hours ago
Martin Perry
1236
1236
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
6
down vote
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.
More: 1, 2, 3
add a comment |Â
up vote
2
down vote
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
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably trystrace
as in Goro's answer first.
â Henrik
4 hours ago
@Henrik While debugging, you can runbash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. Thestrace
approach is universal but the output there must be harder to match with the actual Perl code.
â Kirill Bulygin
2 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
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.
More: 1, 2, 3
add a comment |Â
up vote
6
down vote
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.
More: 1, 2, 3
add a comment |Â
up vote
6
down vote
up vote
6
down vote
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.
More: 1, 2, 3
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.
More: 1, 2, 3
answered 5 hours ago
Goro
3,67352053
3,67352053
add a comment |Â
add a comment |Â
up vote
2
down vote
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
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably trystrace
as in Goro's answer first.
â Henrik
4 hours ago
@Henrik While debugging, you can runbash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. Thestrace
approach is universal but the output there must be harder to match with the actual Perl code.
â Kirill Bulygin
2 hours ago
add a comment |Â
up vote
2
down vote
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
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably trystrace
as in Goro's answer first.
â Henrik
4 hours ago
@Henrik While debugging, you can runbash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. Thestrace
approach is universal but the output there must be harder to match with the actual Perl code.
â Kirill Bulygin
2 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
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
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
answered 5 hours ago
Marvin
512
512
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably trystrace
as in Goro's answer first.
â Henrik
4 hours ago
@Henrik While debugging, you can runbash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. Thestrace
approach is universal but the output there must be harder to match with the actual Perl code.
â Kirill Bulygin
2 hours ago
add a comment |Â
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably trystrace
as in Goro's answer first.
â Henrik
4 hours ago
@Henrik While debugging, you can runbash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. Thestrace
approach is universal but the output there must be harder to match with the actual Perl code.
â Kirill Bulygin
2 hours ago
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably try
strace
as in Goro's answer first.â Henrik
4 hours ago
But the output from the script will be captured by cron, so to actually see this you either need to look at the file descriptors used for that communication or convince cron that the script is done so it will send a mail with the output, hopefully killing it will be enough for that, but I've never tried. And as the OP said it was only about 1% of the invocations that didn't terminate in time, this could generate a lot of output before anything useful. I would probably try
strace
as in Goro's answer first.â Henrik
4 hours ago
@Henrik While debugging, you can run
bash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. The strace
approach is universal but the output there must be harder to match with the actual Perl code.â Kirill Bulygin
2 hours ago
@Henrik While debugging, you can run
bash -c 'perl -d:Trace program 2>&1 | tee /tmp/program.$$'
to capture the output. And it doesn't matter much if many of generated files here are useless. The strace
approach is universal but the output there must be harder to match with the actual Perl code.â Kirill Bulygin
2 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f470681%2fperl-script-running-infinitelly-how-to-debug-what-happen%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password