Is there a way to persistently display background jobs?

・1 min read

I'd like to get into the habit of suspending my editor instead of opening a new shell. Sometimes I forget that I have already started my editor and I'll have several processes running. With my setup, this could turn into a problem if I'm modifying files open in other processes.

I was thinking it would be nice to have a list of background jobs in my prompt, or maybe just some sort of indicator that I have a job suspended.

Even better, I could open a tmux pane and run the jobs command. However, I'd like this to be "persistent" like when tailing a log. Is there a way to keep jobs running in "watch mode"?

DISCUSSION (6)
 
➜  ~ cat > t.txt
test
➜  ~ vim t.txt &
[1] 58870
➜  ~
[1]  + 58870 suspended (tty output)  vim t.txt
➜  ~ jobs
[1]  + suspended (tty output)  vim t.txt

is this what you're looking for?

I would rely with a tmux and maybe name tmux sessions with what you're working on in each of them

 

If you launch everything with screen, you can suspend terminals and then recall them at any point. screen also has a list feature that shows you all the suspended screens.

linux.die.net/man/1/screen

tmux should also have some options but I can't speak to it for sure.

 

You can try first with byobu (byobu.co/) that is more or less a wrapper of screen with an easier learning curve and if you like it then try screen that usually it is already installed on most distros and therefore you can use it on almost any system.

 

You can add \j to your bash prompt. It will show the number of background jobs. More on it here

 

This is very easy when you come with unix tool called: tmux
On macos: brew install tmux
On ubuntu: apt-get install tmux

Usage:

New tmux session:
tmux new -s my-bg-task

Detach current session: ctrl+b d
Attach to detached session: tmux attach -t my-bg-task

 

You can use watch command like this:
watch -n1 jobs

Just split tmux screen and launch this command in one panel.

Classic DEV Post from Dec 4 '18

Idiomatic Ruby: writing beautiful code

Ruby is a beautiful programming language. According to Ruby’s official web pag...

TK
Software Developer, Scientist, Story-teller