Search code examples
shvips

How to close programs running in the background


when I do ps I see vi Dockerfile running how do I close it?

I tried q! in the vi editor but doesn't seem to work.


Solution

  • Before killing the process like suggested in the comments, you could try to get it from the background to the foreground with the command fg.

    After bringing it to the foreground you can close the program like you would normally do. In case of vi with:

    • :q if you have no changes made to the file
    • :qw if you have made changes and want to keep them
    • :q! if you have made changes but don't want to keep them.

    If fg doesn't work you can use kill or killall like suggested in the comments.

    I prefer kill, because it only kills the process you choose. Find process:

    $ ps -ef | grep <e.g. program_name>
    

    Example output:

    user  15256 31598  0 14:41 pts/0    00:00:01 program_name
    

    Kill process:

    $ kill 15256