-->

Parallel::ForkManager demystified

The aim of this post is to check if Parallel::ForkManager always runs the maximum number of processes simultaneously. Suppose one of the processes finish early but the rest continue, will another process be created immediately so that the number of processes becomes equal to the maximum number of processes?

Let us have a look at a script that forks 10 processes:

Output

Each line of the output is of the format:

[time in seconds since the epoch] - [Started|Finished]: [Process ID]

Consider the sleep intervals (in seconds) again: 1, 1, 5, 5, 4, 5, 6, 7, 8 and 9. This means that our first and second processes should sleep for 1 second each before finishing. Similarly, the third and fourth processes should sleep for 5 seconds each, the fifth should sleep for 4 seconds and so on.

The first four lines of the output state that four processes with process IDs 4229, 4230, 4231 and 4232 are created.

1330656252 - Started: 4229
1330656252 - Started: 4230
1330656252 - Started: 4231
1330656252 - Started: 4232

The next four lines:

1330656253 - Finished: 4229
1330656253 - Finished: 4230
1330656253 - Started: 4233
1330656253 - Started: 4234

The first and second processes (4229 and 4230) finished after 1 second (the sleep interval assigned for them). This can be confirmed by doing the simple arithmetic: 1330656253 - 1330656252 = 1. As soon as these processes are finished, two other processes are forked (4233 and 4234) so that the number of parallel processes is always 4.

Perl Weekly: A Free, Weekly Perl Email Newsletter

I will like to introduce you to Perl Weekly:

A free, once a week e-mail round-up of hand-picked news and articles about Perl.

Perl Weekly is managed by Gabor Szabo of Perl Training Israel.

Perl Weekly will help you keep up to date with the latest happenings in the Perl community from around the world. It features news about conferences and workshops so that you do not miss one. Articles superficially related to Perl are featured as well, to give rise to new ideas, borrow existing ideas from other communities or start discussions.

Personally, I was able to learn and get ideas from the articles that were featured. Hence I recommend that you subscribe to it. If you have not subscribed to the e-mail newsletter yet, you may do so at: Perl Weekly. All past issues are archived. Latest issue (week 8).

Start blogging about Perl so that your articles will also be featured in Perl Weekly which is currently read by more than 990 subscribers (and steadily increasing).

svn: Directory .svn containing working copy admin area is missing

While working with Subversion, I removed a directory (specifically .sass-cache/) after placing it under version control without knowledge. Subversion failed to commit. I had to forcefully remove the already removed file to proceed.

svn remove --force .sass-cache/

SSH Hosts

Why should ssh shell.example.com -p 2345 -l example be used when you can use ssh shell?

Create $HOME/.ssh/config file if it does not already exist. Populate it with the following data:

Host shell
User example
Hostname shell.example.com
Port 2345

That is it! You can now just ssh shell.

Finding the latest linux kernel version

I always like to run the latest linux kernel. I found that I kept checking http://kernel.org/ at regular intervals. Thus this script was born: latest_kernel.pl.

WWW::Rapidshare::Free

Just released WWW::Rapidshare::Free Perl module for all free users of Rapidshare. Check out the example/ directory for a sample script. You can expect a GUI soon!

Christmas Tree

perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'

Checking External (WAN) IP

You can use:

curl whatismyip.org
wget -qO - whatismyip.org

There are many other ways too.

General Purpose Bit Flag not being set

This is an unreported bug in the Archive::Zip Perl module. This means that the level of compression will not be stored in the archives that are created, which may cause trouble with some extractors while inflating. PKWARE’s application note on the .Zip file format states that these flags should be set.

Please see: Update on General Purpose Bit Flag bug and Archive::Zip does not set General Purpose Bit Flag.

Bash Completion

Bash completion is a very good feature in Bash. We are able to complete filenames, just by pressing TAB. I had downloaded a YouTube video related to Tsar Bomba. Since YouTube videos are Flash Video files (.flv), I was not able to complete their filenames by pressing TAB in the terminal when trying to invoke mplayer.

A quick inspection of /etc/bash_completion solved the problem.

In mplayer(1) completion section,

_filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fli|FLI|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[34]|MP[34]|og[gm]|OG[GM]|wav|WAV|dump|DUMP|mkv|MKV|m4a|M4A|aac|AAC|m2v|M2V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3gp|mpc|MPC|flac|FLAC|flv)'

flv was appended at the end. That was it. Problem solved! Happy viewing!