Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Oct 8 '12 at 11:38

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

2 Answers 2

up vote 3 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).

addenda

(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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.