Super “strace” perl script to assist with debugging programs that spawn child processes.

If you have ever ran into a problem with trying to strace apache or other processes that spawn children, then this script will help you out greatly. This small perl script will grab all of the PID’s of the current process and its children and then run an strace command on all of them to provide strace output from all of apache. You can modify the strace line to your liking as well as the log names, by default it logs to a file based on date and time to the /tmp directory. Code included, click ‘Read More’.

If you have ever ran into a problem with trying to strace apache or other processes that spawn children, then this script will help you out greatly. This small perl script will grab all of the PID’s of the current process and its children and then run an strace command on all of them to provide strace output from all of apache. You can modify the strace line to your liking as well as the log names, by default it logs to a file based on date and time to the /tmp directory. Code included, click ‘Read More’.


#!/usr/bin/perl

# Do we have any input?
if(!$ARGV[0]) {
print "Super strace, will strace a running application and all of its children.\nUsage: $0 \nExample: $0 apache2\n";
exit;
}
# get the data we need!
@pids = `pgrep @ARGV[0]`;
# this is the old method, if pidof doesn't exist uncomment if the above breaks
#@pids = `ps auxwwf | grep apache | awk \'\{ print \$2\}\'`;
# get some variables for the current time! Gotta be iso 8601 YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
#my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
$date = `date +%FT%H:%M:%S%:z`;
chomp ($date);
#$year += 1900;
#$mon += 1;
#$date = "$year-$mon-$mdayT$hour:$min:$sec";
# the strace command! this can be replaced with any command
$go="strace -f -s 40000 -o /tmp/sstrace-$date";
# the separator
$sep = " -p ";
$i=0;
foreach $pid (@pids) {
chomp ($pid);
$go = $go . $sep . $pid;
$i++;
}
print $go . "\n";
exec $go;


Did you like this article?


0 Shares:
You May Also Like

Comcast fires employees for talking about P2P filtering

It looks as though Comcast has fired a few employees for talking out of script.
In the wake of the discovery that Comcast is blocking some peer-to-peer traffic (and even blocking some Lotus Notes e-mails), the company is attempting to keep the PR machine well-oiled by giving customer tech support reps some talking points. And if they deviate from the script and admit that Comcast has been using Sandvine to send forged TCP reset packets, they're likely to lose their jobs.
Read More

Setting up daily, weekly and monthly MySQL Database Backups using AutoMySQLBackup

AutoMySQLBackup is a shell script that allows daily, weekly and monthly backups of your local and remote MySQL Databases. It's meant to run on Linux/Unix through a cron job. Its highly configurable, and easy to setup as I will show you today! First you will need to acquire the shell script and drop it on your server. You can download AutoMySQLBackup on their SourceForge Project Page
Read More