Suspending in Bash: Quickly switch between running processes in bash

Suspending in Bash: Quickly switch between running processes in bash Thumbnail image

This is just a quick post, but if you've ever been doing something in the terminal, for example you were editing a file (vim somefile.txt), but you wanted to return back to the main command line, then you can do the following:

Press ctrl + z - this will suspend the current job (current process) - although sometimes, such as in Vim in insert mode, it won't always work. You should return to the main command line. Do whatever you want to do. Then to get back to that process type fg (for foreground).

To see all suspended processes, use the jobs command.

If you want to go back into a specific job then get it's ID (from the jobs command), and type fg 123, where 123 is that ID.

An alternative is to use screen (and it is always a good idea to use screen if you are connection is a bit dodgy and you're connecting via ssh to another server, so you can pick up where you left off if your connection dies.)

If you want to start a program and push it directly into the background, then you can do ./someScriptOrProgram.sh & (add a ampersand to the end of it).

webdevetc profile pic
webdevetc

I am a 29 year old freelance backend web developer from London, mostly focusing on PHP and Laravel lately. This is my site - I mostly write about PHP here. Contact me here (especially for any contracting jobs early 2019 in London ;) ).

Leave a Comment