Ubuntu – How to do when I get ‘There are stopped jobs’ error

emacsjob-controlprocess

I face this type of situation many times.

For example, whenever I try to open some file in emacs with sudo rights using:

sudo emacs tet.c &

Instead of asking me for the password Ubuntu just starts emacs process without any emacs window or any output on terminal (except for the pid) see the image (if I don't use '&' then it will ask me for the password):

enter image description here

I have two questions related with this:

  1. What should I do when I get error that 'There are stopped jobs'? How
    do I identify all such stopped jobs and kill them? Once I clear the
    terminal I won't have pids of these stopped processes.

  2. Why is Ubuntu/emacs behaving like this? Why doesn't it ask me for
    the password?

Best Answer

There are stopped jobs message is far, far away to be an error. It's just a notification telling you that you attempt to exit from the shell, but you have one or more suspended jobs/programs (in your case emacs which you putted in background using & at the end of your command). The system doesn't let you to exit from the shell and kill the jobs unless you mean to. You can do a couple of things in response to this message:

  • use jobs command to tell you what job(s) you have suspended
  • you can choose to add the job(s) in the foreground using fg command
  • if you don't care if the job(s) will terminate, you can just type exit again; typing exit a second time with or without an intervening jobs command will result in the termination of all suspended jobs.

To answer the second question, I will tell you that not Ubuntu or emacs behaving like this. This is a normal behavior when you put an application to run in background. In this case sudo is asking for password, but is asking in background, so you can't see this fact. To see it, you should bring back the job in foreground using fg command:

radu@Radu: ~ $ sudo emacs tet.c &
[1] 7732
radu@Radu: ~ $ # now sudo emacs run in background so you can't see nothing about what's happening
radu@Radu: ~ $ fg
[sudo] password for radu:

After this you can type Ctrl+Z to put again the job in background if you want. Then you can run again 'fg' command to bring back the job in foreground and so on.