Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on a existing linux based script where it contains the following content

pid=`jps | grep TestServer | awk '{print $1}'`
kill -9 $pid

I understand that this will kill this process named 'TestServer'

I am new to Linux and i am trying to understand the script , so please excuse if this is a dumb question .

Please tell me Who is responsible to set the Process name "TestServer"

share|improve this question

migrated from Oct 8 '12 at 11:38

This question came from our site for professional and enthusiast programmers.

up vote 4 down vote accepted

A process don't have any name. It has a (positive) unique number, called its pid (process id).

Almost all processes are started -from their parent process- by the fork system call documented in the fork(2) man page (sometimes, vfork(2) might be used). A forked process is nearly identical to its parent (it executes the same binary). To execute a new program, the execve(2) syscall is used inside some process.

However, a process does execute some program, which does have a name (since it exists in the filesystem). You can find much more about processes thru the proc(5) pseudo-file system. Of course, several processes could execute the same program. You could try ls -l /proc/self/ to list the pseudofiles related to your process (the one executing that ls command). You might have fun trying cat /proc/self/maps. And /proc/1234/ tells you about process of pid 1234.

The pkill, pgrep, pidof utilities are using /proc.

I suggest you to read a good book on advanced unix programming -on paper- and on advanced Linux programming -on the web-; Read also about syscalls(2), also the wikipage on syscalls.

Your script is not right in using directly kill -9. It should try first kill -TERM then kill -QUIT (to let the program terminates nicely, e.g. cleaning temporary files, etc...) and only at last kill -KILL (i.e. kill -9). You could read the kill(2) man page (and also signal(7) man page).


(added in july 2014)

On Linux, you could use the Linux-specific pthread_setname_np(3) function to set a short name of a thread (not a process)

share|improve this answer

The name comes from the name given to the program. So whatever the file containing the executable is called. If the file is called fred, the process name will be fred.

A better way to kill the process by name is to use pkill.

pkill TestServer
share|improve this answer

You must log in to answer this question.