What is the meaning of kill %1

13

2

I have seen the following command:

$ kill %1

What is the usage of this statement?

q0987

Posted 2011-07-30T22:37:32.470

Reputation: 786

1"I've just sucked one year of your life away" – dmckee --- ex-moderator kitten – 2011-07-30T22:49:56.027

Note also that zsh has job completion, such that running htop & and then disown %[TAB] will autocomplete to disown %htop. I love zsh :) – new123456 – 2011-07-31T02:40:05.880

Answers

17

Briefly,

It means to kill job number 1, not process number one.

Jobs can be listed with the jobs command.

More broadly, it relates to whichever shell you are using, and the syntax could differ from shell to shell.

Using the bash shell, a user can have several processes (jobs) executing simultaneously, whose parent process is the shell you are using. Google bash job control basics

The builtin kill command is used to send a signal to one of those job pipelines. If the specific signal is not specified, SIGTERM is used, which typically ends (kills) the job, hence the name kill. But any signal can be specified some of which might somehow reset the process or cause non-killing behavior.

Finally, the %1 is one way (of many!) of specifying which job you wish to send the signal to. %1 refers to the job on top of the stack of background jobs.

Anders Abel

Posted 2011-07-30T22:37:32.470

Reputation: 391

Minor..but it is not a stack, it is like a queue. – endless – 2015-12-06T23:21:57.440

6

When you background a process for example:

# find / &
[1] ....

# ls -lr /usr &
[2] ....

Now, Here there are two processes running in background and connected to the current terminal. If you do: kill %1

the first, 'find' command above will get terminated. As told by Anders you can list the currently running background processes on the terminal and kill them:

# jobs
[1] find / ...
[2] ls -lr ...

# kill %1

Albert

Posted 2011-07-30T22:37:32.470

Reputation: 61