bash

kill a process in bash


How do I kill a process which is running in bash - for example, suppose I open a file:

$ gedit file.txt

is there any way within the command prompt to close it? This example is trivial, since I could just close the window, but it comes up a bit, particularly when I mistype commands.

Also is there any way to escape an executable which is running?


Solution

  • To interrupt it, you can try pressing ctrl c to send a SIGINT. If it doesn't stop it, you may try to kill it using kill -9 <pid>, which sends a SIGKILL. The latter can't be ignored/intercepted by the process itself (the one being killed).

    To move the active process to background, you can press ctrl z. The process is sent to background and you get back to the shell prompt. Use the fg command to do the opposite.