From: Andi Kleen This patch adds a prctl to modify current->comm as shown in /proc. This feature was requested by KDE developers. In KDE most programs are started by forking from a kdeinit program that already has the libraries loaded and some other state. Problem is to give these forked programs the proper name. It already writes the command line in the environment (as seen in ps), but top uses a different field in /proc/pid/status that reports current->comm. And that was always "kdeinit" instead of the real command name. So you ended up with lots of kdeinits in your top listing, which was not very useful. This patch adds a new prctl PR_SET_NAME to allow a program to change its comm field. I considered the potential security issues of a program obscuring itself with this interface, but I don't think it matters much because a program can already obscure itself when the admin uses ps instead of top. In case of a KDE desktop calling everything kdeinit is much more obfuscation than the alternative. Signed-off-by: Andrew Morton --- 25-akpm/include/linux/prctl.h | 2 ++ 25-akpm/kernel/sys.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff -puN include/linux/prctl.h~add-prctl-to-modify-current-comm include/linux/prctl.h --- 25/include/linux/prctl.h~add-prctl-to-modify-current-comm 2004-09-11 17:26:30.062064568 -0700 +++ 25-akpm/include/linux/prctl.h 2004-09-11 17:26:30.067063808 -0700 @@ -49,4 +49,6 @@ # define PR_TIMING_TIMESTAMP 1 /* Accurate timestamp based process timing */ +#define PR_SET_NAME 15 /* Set process name */ + #endif /* _LINUX_PRCTL_H */ diff -puN kernel/sys.c~add-prctl-to-modify-current-comm kernel/sys.c --- 25/kernel/sys.c~add-prctl-to-modify-current-comm 2004-09-11 17:26:30.064064264 -0700 +++ 25-akpm/kernel/sys.c 2004-09-11 17:26:30.068063656 -0700 @@ -1775,6 +1775,16 @@ asmlinkage long sys_prctl(int option, un current->keep_capabilities = arg2; break; + case PR_SET_NAME: { + struct task_struct *me = current; + unsigned char ncomm[sizeof(me->comm)]; + ncomm[sizeof(me->comm)-1] = 0; + if (strncpy_from_user(ncomm, (char *)arg2, + sizeof(me->comm)-1) < 0) + return -EFAULT; + memcpy(me->comm, ncomm, sizeof(me->comm)); + return 0; + } default: error = -EINVAL; break; _