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

CE-Oh no he didn’t, part XXXV: NBC sez piracy hurts ‘corn growers’

CE-Oh no he didn't, part XXXV: NBC sez piracy hurts 'corn growers' -

Filed under: ,

Although some may argue that piracy is (at least on some level) beneficial, it looks like NBC has taken that sentiment to the opposing extreme with its latest comments. In a purported filing with the FCC calling for enhanced regulation of the internet in an attempt to stifle evil P2P activity, NBC blurted out a string of text that it surely hoped would be overlooked. Alas, hardly any ridiculous claims go unseen these days, so now we're faced with this gem: "In the absence of movie piracy, video retailers would sell and rent more titles. Movie theaters would sell more tickets and popcorn. Corn growers would earn greater profits and buy more farm equipment." There's absolutely no need for us to pick apart the aforementioned quote, after all, we're fairly certain the absurdity shines right through on its own.

[Via TechDirt, image courtesy of Monsanto]

 

Read | Permalink | Email this | Comments


Office Depot Featured Gadget: Xbox 360 Platinum System Packs the power to bring games to life!

[EnGadget]
Read More

Microsoft Pleads With Consumers to Adopt Vista Now

I for one am currently at torn between XP and Vista. I like XP because it doesn't crash, my drivers work. However, more people keep asking for help with Vista, and I haven't even logged into a Vista Machine yet. :(
Microsoft Pleads With Consumers to Adopt Vista Now - SlinkySausage writes "Microsoft has admitted, in an email to the press, that 'some customers may be waiting to adopt Windows Vista because they've heard rumors about device or application compatibility issues, or because they think they should wait for a service pack release.' The company is now pleading with customers not to wait until the release of SP1 at the end of the year, launching a 'fact rich' program to try to convince them to 'proceed with confidence'. The announcement coincides with an embarrassing double-backflip: Microsoft had pre-briefed journalists that it was going to allow home users to run Vista basic and premium under virtual machines like VMWare, but it changed its mind at the last minute and pulled the announcement."

Read more of this story at Slashdot.

[Slasdot]
Read More