mono-list  

Re: [Mono-list] Change mono process name in ps/top

Robert Jordan
Sat, 23 Jan 2010 05:22:09 -0800

On 23.01.2010 06:02, Bryan Murphy wrote:
> Is there a way I can change the name of a mono process for when I'm looking
> at it via ps or top?

First, there is no portable way to change the process name.

Under Linux, prctl(2) can be used to change the name. It seems
that "ps" is still showing the command line, whereas "top" is
actually considering the new name.

Robert

----
using System;
using System.Runtime.InteropServices;

class Programm
{
        static void Main ()
        {
                LinuxProcCtl.SetProcessName ("rootkit");

                for (;;) {
                        // busy loop to be on top of "top" ;)
                }
        }
}

public static class LinuxProcCtl
{
        /* see linux/prctl.h */
        const int PR_SET_NAME = 15;
        
        [DllImport("libc")]
        static extern int prctl(int option, string arg2,
                                IntPtr arg3 , IntPtr arg4, IntPtr arg5);

        public static bool SetProcessName (string name)
        {
                return prctl (PR_SET_NAME, name, IntPtr.Zero, IntPtr.Zero, 
IntPtr.Zero) == 0;
        }
}
----

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list