Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Feb 132010
 

How to shutdown a frozen Linux System?

Answer:

Similar to this post, but this time you are going to shutdown a frozen Linux system.

  1. Hold down the Alt and SysRq (Print Screen) keys
  2. While holding those down, type the following in order: REISUO
  3. You computer will shutdown now

The last letter O tell the system to shutdown. Replace by the letter R if you want reboot instead.

Feb 122010
 

Benchmark Perl subroutines

Answer:

The Benchmark module provide a very easy way to compare (cmpthese) the performance of Perl's subroutines.

E.g. The following codes compare the performance of MD5 and SHA1 hashing methods.

#!/usr/local/bin/perl

use strict;
use Benchmark qw(cmpthese);
use Digest::MD5  qw(md5_hex);
use Digest::SHA1  qw(sha1_hex);

my $str = '83b0c3d63e8a11eb6e40077030b59e95bfe31ffa';
my $s;

cmpthese( 1_000_000, {
    'md5' => sub{ $s = md5_hex($str) },
    'sha1' => sub{ $s = sha1_hex($str) }
});

It will output

# perl compare_md5_sha1.pl

Rate sha1  md5
sha1  934579/s   -- -39%
md5  1538462/s  65%   --

Obviously, MD5 is faster than SHA1.

Feb 122010
 

Turn on expire headers in Apache

Answer:

By turning on the expire headers, browser will cache the files serving from Apache more aggressively, so as to reduce traffic loading to the Apache web server.

Steps:

Add the following lines to the Apache configuration (httpd.conf)

<IfModule mod_expires.c>
    ExpiresActive On

    # Cache all files for 2 weeks after access (A).
    ExpiresDefault A1209600
    
    # Do not cache dynamically generated pages.
    ExpiresByType text/html A1
</IfModule>

Restart Apache to take effect

# apachectl -k graceful

Assume the module mod_expires is enabled

Feb 122010
 

Convert HTML to image

Answer:

Firstly, you need to install html2ps

# sudo apt-get install html2ps

Then install the ImageMagick

# sudo apt-get install imagemagick

Finally run the command:

# convert -density 72 input.html output.png