Multithread programming with Bash (and other shell), Sema4shell

frenchIl y a également une version en français de cet article

Most of today computer has got several core in their CPU, today I wanted to accelerate some hard computing tasks that are done in a monothread, by dispatching them on 4core computer (my atom330 64bits ultra-low voltage and low-cost deskstation has 4 core and several servers have 2 to 8 cores).

I remember the old day of funny coding with BeOS on BeBox first two-CPU personal computer. I thought it could be cool and fun to reuse those technics on today computers.

I was astonished by the lake of semaphore management on Bash and other shell. Then I written these POSIX atomic semaphore API binding to be able to use more resources in parallel. This is a quick’n'dirty coding, without comments, with commented printf, without return code testing, but working enough for simple use. It only manage named semaphores (Linux-2.6 minimum), I will try to add more functions or aggregate them in a single command later.

You can download sema4shell (sema(phore/ for) shell) here. (updated to 0.3, march, 17 2009)

You can read the included README, included example and the sem_overview man page to understand the POSIX implementation.

Leave a comment

You must be