Changing process name in Mono

Banshee 0.10.5 supports changing the process name from “mono” to “banshee” using the prctl call. This makes “killall banshee” work. While this is nothing to marvel over, I have been a little taken aback by the amount of inquiry over this feature. In the past few days, a large number of people have asked me, “how did you do this.” Here’s a brief description of “how.”

This had been discussed over private email a few months ago, but was recently touched on again as a bug filed against Beagle.

The short answer is, if you want your mono app to be “killall-able,” then do this:

using System.Runtime.InteropServices;
using System.Text;

...

[DllImport ("libc")] // Linux
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, 
    IntPtr arg4, IntPtr arg5);

[DllImport ("libc")] // BSD
private static extern void setproctitle (byte [] fmt, byte [] str_arg);

public static void SetProcessName (string name)
{
    try {
        if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"), 
            IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
            throw new ApplicationException ("Error setting process name: " + 
                Mono.Unix.Native.Stdlib.GetLastError ());
        }
    } catch (EntryPointNotFoundException) {
        setproctitle (Encoding.ASCII.GetBytes ("%s\0"), 
            Encoding.ASCII.GetBytes (name + "\0"));
    }
}

...

try {
    SetProcessName ("banshee");
} catch (Exception e) {
    Console.Error.WriteLine ("Failed to set process name: {0}", e.Message);
}

Now “killall banshee” works. Also consider using “exec -a banshee ...” in your Bash wrapper to make process listings look better. There are more details provided in the bug, as well as some implications you should be aware of if you do this with your Mono app.

Code snippet updated on 2007-11-12 to show how to support BSD systems and reflect a known fix for 64 bit systems. The above code is known to be bug free and tested in many production applications.

Banshee 0.10.5: Heart Attack Fries

This just in: moments ago Banshee 0.10.5 hit the banshee-project.org server. Nothing major in terms of features. The new database layer is pretty sexy though. All queries are queued and processed on a single thread, so locking is no longer a potential issue. Also, a new official plugin, by Danilo Reinhardt, was added that allows for special multimedia key support, configurable through the Gnome keyboard shortcuts capplet. As always, the scandalous details are in the release notes.

I noticed today that the Banshee last.fm group has grown to 125 members. Not bad for ~1.5 months. Sweet.

Photo of Heart Attack Fries

Fries, liquid cheddar, cut up burger, bacon, grilled onions… mmmmmm.

I am on a quest

A few weeks ago, some friends and I decided to have lunch at Ruby Tuesdays. My mission was clear: conqueror the 1 lb burger. Simple. It was amazing, and I am now on a quest for bigger, badder burgers. Perhaps one day, I will dominate this incredible hunk of heart-attack.

The 1lb RT burger

Earlier this week I was a bit spaztastic, obsessing over including SexyIconEntry as the search widget in Banshee, amazed by how much it had improved over the last few months. While this may happen in a future release, I’m holding off on comitting that patch as I really don’t want to make libsexy a dep right now. However, in the process I decided to write GAPI-based C# bindings to libsexy, which are now available in the libsexy-mono module Christian’s SVN repo.

Banshee with libsexy's SexyIconEntry

Jon has been doing some really cool work with a new Banshee source plugin. I’m sure there will be more on this later :-). Also, Fredrik has been hacking on Jon’s SharpMusique to create a Banshee plugin (SharpMusique is an iTms client, and allows purchasing music using your Apple account from the iTunes Music Store). He committed a first pass of the integration plugin (svn co svn://abock.org/trunk/banshee-itunes-plugin), for anyone who wishes to test. At the moment there is no menu integration, and you can only purchase one track at a time, and if you’ve used iTunes 6, your account is flagged, and will not allow purchases (yet). Nonetheless, this is an excellent start :-D

Banshee iTms Plugin

Also last week, I discovered X-Moto and have a new addiction to add to my collection.

X-Moto is super

That is all.