Linux Today: Linux News On Internet Time.

More on LinuxToday

Demonstrating multi-processing in Bash 4

Jul 29, 2010, 16:06 (0 Talkback[s])


Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers

"I have an on-going project, to code the Collatz sequence in as many languages as I can. So far, I've implemented it in C (integer and floating-point), assembly (x86, x86_64, and SPARC32), Java, BASIC in Open Office.org, Tcl, Lisp, Ada, Python, and Bash. Naturally, the fastest method is assembly, which can by-pass all the cautions of the other, translated languages.

"One point I've given myself extra credit for, is to use both cores on my AMD Athlon64 X2, making sure to print out results in order. Different languages have different ways to do this. (Python has the most elegant method I've seen, using a source array and a result array, and calling Pool() to dispatch the next iteration to whichever CPU just became available, until all results are finished. However, this means deferring printing the results until the entire result set is available.)

"Bash has had multi-processing for a long time, via job control, the $! environment variable, and the wait command. Judicious use of parentheses for sub-processes, and pipes where necessary, can put comparatively long-term procedures into the background. One example of this is the time-of-day monitor I used in my holiday slideshow."

Complete Story

Related Stories: