Welcome to

Can your cell phone do this?

Not too long ago, I picked up a Nokia N900 cell phone. This device is truly unique; it runs Linux! Well, of course, that's not unique -- all Android devices are running Linux under the hood. The difference with the N900 is that it doesn't have Linux hidden away in a locked area deep beneath layers of strange iPhone-like graphical interfaces; no, with the N900 you're running a normal, straight-up Linux distribution. (This one is called "Maemo", and was created by Nokia themselves.)

So, I've been having fun writing some code for the device. My main project has been a little remote-control app (as the N900 comes with an IR LED). (Check out either the Pierogi garage page or the Maemo app site for more details. I'm hoping to have a new, cleaner website up and running soon...) One of the first things I needed to do was to gain access to the LED device. How to do that? Well, this is Linux; there is a device driver (/dev/lirc0) in the file system set up to control the IR hardware. Open it as you would any other file, write your commands into the file, and close it. And you're done! No muss, no fuss.

Well, there was one precondition required; if the device driver hadn't been initialized yet, I needed to do it manually. As with most modern Linux distributions, device drivers are now "modular" and are normally not set up until they are needed. The usual way to do this is to run the utility "modprobe". I eventually created a script for myself to load and unload the module as needed, but how should I run that script from within my app? Well, in the obvious manner: fork() and exec()!

pid_t pid = fork(); if (pid == -1) { return -1; } else if (pid == 0) { // We're inside the child process, so exec the load module script: execl( "/usr/bin/sudo", "/usr/bin/sudo", "/opt/pierogi/bin/loadRX51Module", NULL); }

Yes, you read that right -- Maemo allows applications to create child processes, and to run these processes in parallel; in short, full-fledged desktop-quality multitasking! Take that, iOS / Android / Windows Phone!

Webmaster mail address: john@pietrzak.org
Page last modified: 12/4/2010