8

I have seen the following command:

$ kill %1

What is the usage of this statement?

migrated from stackoverflow.com Jul 30 '11 at 22:39

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

13

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.

  • Minor..but it is not a stack, it is like a queue. – endless Dec 6 '15 at 23:21
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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.