[Mono-list] Change mono process name in ps/top
Robert Jordan
robertj at gmx.net
Sat Jan 23 08:21:38 EST 2010
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;
}
}
----
More information about the Mono-list
mailing list