25

I have seen the following command:

$ kill %1

What is the usage of this statement?

2

2 Answers 2

28

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.

1
  • Minor..but it is not a stack, it is like a queue.
    – endless
    Dec 6, 2015 at 23:21
9

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .