Lucas Ou-Yang
Lucas Ou-Yang

Reputation: 5655

Confusion with pid's and processes on linux

from reading docs and online most people have been saying that to kill a process in linux, only the command kill "pid" is needed.

For example to kill memcached would be kill $(cat memcached.pid)

But for pretty much every process that i've tried to kill including the one above, this would not work. I managed to get it to work with a different command:

ps aux | grep (process name here)

That command, for whatever reason would get a different pid, which would work when killing the program.

I guess my question is, why are there different pid's? Isn't the point of an id to be unique? Why do celery, memcached, and other processes all have a different pid's when using the aux | grep command, versus the pid in the .pid file? Is this some kinda error on my configuration or is it ment to be like this?

Also, where is it possible to get all arguments and descriptions for an executable in linux?

I know the "man" command is useful for some functions, but it wont work for many executables, like celery for example.

Thanks!

Upvotes: 0

Views: 327

Answers (1)

chrisaycock
chrisaycock

Reputation: 37930

The process ID (pid) is assigned by the operating system on-the-fly when a process starts up. It's unique in the sense that no two processes have the same ID. However, the actual value is not guaranteed to be the same from one run of the process to another. The best way to think of it is like those "now serving" tickets:

please take a number

You are correct that you can look up an ID via ps and grep, though you may find it easier to just use:

pgrep (process name here)

Also, if you just want to kill the process, you can even skip the above step and use:

pkill (process name here)

Upvotes: 1

Related Questions