Oct
31
2007
So far, Lee's Code Highlighter is the best I found. Download it at http://ideathinking.com/wiki/index.php/WordPress:CodeHighlighterPlugin
To install the plugin:
- Unzip the plugin archive
- Upload the directory to the /wp-content/plugins/ directory
- Activate the plugin through the 'Plugins' menu in WordPress
It is useful to add a border on the code section. To achieve so, in your themes folder /wp-content/themes/yourTheme/
Add the following to your style.css
pre {
font-size: 12px;
background:#f8f8f8;
padding:4px;
border:#c96 1px dotted;
}
Oct
31
2007
Sometimes we need to start a background process to do a long-running job, while the parent process may die before the child dies. To do so in Perl, you can use the following code:
#!/usr/bin/perl -w
use strict;
use POSIX qw(:sys_wait_h);
my $kidpid;
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die ("Failed to fork");
exit;
} elsif ($kidpid == 0) {
# fork returned 0, so this branch is child
exec("./longjob.pl");
exit;
} else {
# parent
$SIG{CHLD} = sub { 1 while ( waitpid(-1, WNOHANG)) > 0 };
print "Parent exited\\n";
exit;
}
If the parent is a web server process and writes back a html page, it might not return immediately. The solution is to close the STDIN, STDOUT, and STDERR in the child process.
#!/usr/bin/perl -w
use strict;
use POSIX qw(:sys_wait_h);
my $kidpid;
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
die ("Failed to fork");
exit;
} elsif ($kidpid == 0) {
# fork returned 0, so this branch is child
close (STDIN);
close (STDOUT);
close (STDERR);
exec("./longjob.pl");
exit;
} else {
# parent
$SIG{CHLD} = sub { 1 while ( waitpid(-1, WNOHANG)) > 0 };
print "Parent exited\\n";
exit;
}