Saturday, October 28, 2006

shell: parallel execution with timeouts

From time in time I was looking how to run a command with a timeout (in a shell script). I never put big efford to find the solution, because I always found a easyer (and probably better) workaround. But few days ago, in a discussion in the austing group (POSIX standardization), I found the solution, in an elegant manner, and it permit also to run commands in parallel.

The solution (it works on bash, dash, and it seems posix compatible, but you should test, because the discussion was about the different behaviours of $! in bash and kornshell):
 # run command1 in background, and the sleeping killer
command1 &
( sleep 60; kill $pid ) &
# other stuffs
# wait command1
wait $pid

Note: kill (the shell buildin) prints some error messages, which you should filter
Note: Security: the methods is not very clean and secure. If an user can force system to recycle the PID, the scripts could do unintended things.

I this trick can be used to parallel the init script (parallelize within the script, not "run scripts in parallel", as the current trend).
So another short tip: Debian sleep support "floating sleep", so use sleep .1 istead of sleep 1, to speed up the init scripts (module loading, waiting for devices, net,...). Unfortunately most of the debian scripts use integer sleeps.

Wednesday, October 18, 2006

ntp: keeping the right time

This is an other topic inspired by ;login: (usenix magazine). I think it is essential for a computer to have the clock showing the right time, and it is not hard! On my servers I use either ntpd (the daemon), or 4 time per day a ntpdate to a nearly ntp server. On my home desktop the ntpdate is run at every boot (because it is never on for long time), and on my ibook the same on linux boot and ntpd on MacOS (which is the default).
I don't know what is the better method. A drift of one second is mainly acceptable on my machines, so the ntpdate methond should be the better choice (if the hardware clock is not "broken"). [BTW the debian packages are: ntp and ntpdate]

Today I joined the ntp pool servers: a list of public (and unrestricted) ntp servers. For my configuration I choosed 6 ntp servers (stratum 2) located in Switzerland.

If you don't care to high precise timing, you can use ntp pool servers (check the references to choose the right servers). If you have not yet used ntp, it is the better start. For high precise timing, there are also Stratum 1 (but read the usage rules) and Stratum 2. Optionally you can also use a GPS clock.

References: ntp project home page. I've also heard that there is a project of one of the BSD to make an alternate (and lighter) implementation.

Tuesday, October 17, 2006


Yesterday I was looking for the changes between the ANSI/ISO C (1989) and the new C99 (ISO 1999). The best information are found in:
Summary of the main changes:
  • external identifier now are case sensitive and up 31 characters (in old standard a portable program should not rely on case sensitiveness nor to more of 6 chars)
  • variable argument on macros
  • from C++: // comment, inline, declaration and statement can mix, for allow declaration in first "argument"
  • compound literals
  • initializers: int a[10] = { [5] = 3}; struct {int a,b} c = { .b=3};
  • long long (64-bit or longer) with LL, ll, ULL and ull suffixes in costants
  • __func__ "automatic variable" : void f(int void) { fprint("me is %s\n", __func__); }
  • _Bool and if you #include you have bool, true and false
  • restrict keyword to optimize function: you tell compiler that pointers don't point overlapping regions.
  • variable-length arrays
The gcc has a page about what is implemented and what not.

In you see the complete standard with the two corrigenda, and the rationale about the new standard. It worth to browse it!

About me

As first post, I'll describe briefly me and my interest. I'm Swiss, I spoke Italian (mother tongue), French, German and English. Maybe this blog would improve my English skills.

I'm a Debian Developer (but few packages), I started with Debian in 1996 or 1997 (IIRC) with few floppies disks, than Mandrake (easier to handle packages with floppies), then someone burned my a RedHat, unfortunately with a non free X server, and than I compiled and installed a lot of program from sources (kernel, glibc, gcc...). Finally I used Debian for all home activities as only OS.
Recently with my new laptop (iBook), I use dual boot: MacOS and Linux/Debian.

I install nearly every kernel from "vanilla sources" since 2.0.28/2.1.8x. I read kernel mailing list
since 7-8 years, but I've contributed only with few and small patches.

I focus on kernel, security and standards, but I'm also interested in networks (IP, and the organizations behind Internet: IC, IAB, IETF, ICANN, IANA, RFC-editor,...), configuration and low level libraries.

I'm a wikipedian (now I think I have nearly 1200 edits in the English edition): anti vandalism, clean-up, swiss topics (mainly about Ticino), wine and filmmaking.

I own a small vineyard, and I make also some wine.

And a lot of other "minor" interests.