[Muine] [PATCH] Set the process name



Attached is a patch that sets the process name for the muine process
to "muine". So? I hear you all cry. Well, this allows us to do
"killall muine" and have it only kill muine, as opposed to doing
"killall mono" and seeing half the desktop disappear. It also means
that top reports muine

26595 iain      20   0 89192  45m  20m R  7.6  3.0   0:14.67 muine

like that...
and the change to muine.in (exec -a "muine") allows ps to display it
neatly as well

iain     26624  0.0  1.4  83732 23312 ?        Ss   01:20   0:00 muine
/usr/local/lib/muine/muine.exe

Or neater at least...

I can't claim any of this as my own, see
http://abock.org/2006/02/09/changing-process-name-in-mono/ for more
details.

iain
Index: src/Global.cs
===================================================================
RCS file: /cvs/gnome/muine/src/Global.cs,v
retrieving revision 1.17
diff -U2 -r1.17 Global.cs
--- src/Global.cs	28 Jan 2006 22:25:46 -0000	1.17
+++ src/Global.cs	10 Feb 2006 01:20:45 -0000
@@ -20,4 +20,6 @@
 using System;
 using System.IO;
+using System.Runtime.InteropServices;
+using System.Text;
 
 using Gtk;
@@ -110,4 +112,5 @@
 		public static void Main (string [] args)
 		{
+			Global.SetProcessName ("muine");
 			Application.Init ();
 
@@ -376,4 +379,17 @@
 
 			session_client.SetRestartCommand (1, argv);
+		}
+
+		[DllImport ("libc")]
+		private static extern int prctl (int option,  
+						 byte[] arg2,
+						 ulong arg3,
+						 ulong arg4,
+						 ulong arg5);
+		public static void SetProcessName (string name)
+		{
+			if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), 0, 0, 0) != 0) {
+				throw new ApplicationException ("Error setting process name: " + Mono.Unix.Native.Stdlib.GetLastError ());
+			}
 		}
 	}
Index: src/muine.in
===================================================================
RCS file: /cvs/gnome/muine/src/muine.in,v
retrieving revision 1.10
diff -U2 -r1.10 muine.in
--- src/muine.in	6 Jan 2005 11:22:37 -0000	1.10
+++ src/muine.in	10 Feb 2006 01:20:45 -0000
@@ -3,3 +3,3 @@
 export MONO_GAC_PREFIX=$MONO_GAC_PREFIX:@prefix@
 
-exec @mono@ @mono_flags@ @pkglibdir@/@target@ "$@"
+exec -a "muine" @mono@ @mono_flags@ @pkglibdir@/@target@ "$@"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]