What should I do when I get 'There are stopped jobs' error?
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):
I have two questions related with this:
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.
Why is Ubuntu/emacs behaving like this? Why doesn't it ask me for the password?
3 Answers
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
jobscommand to tell you what job(s) you have suspended - you can choose to add the job(s) in the foreground using
fgcommand - if you don't care if the job(s) will terminate, you can just type
exitagain; typingexita second time with or without an interveningjobscommand 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.
2You got the message, because system warns you about active jobs associated with your current shell.
You can list these running/stopped jobs by running: jobs,
Then you can do one of the following:
- move last job to the foreground by:
fg(opposite ofbgfor background), - run
disownto remove these jobs from your current shell without killing them, - force logout by killing these tasks by pressing Ctrl+D twice, same as typing
exit/logouttwice, - kill these jobs manually by running:
kill $(jobs -p)(add-9for force) if you disown them, and you want to still kill all stopped processes, try:
kill $(ps wuax | awk 'NR>1 && $8 ~ "T" {print $2}')
To answer question about sudo, it won't ask you for the password, as it requires to have active terminal in order to receive the password from standard input, and by running it the background, the shell doesn't wait for the command to finish, so you don't have possibility to interact with the command.
In this case, you've 3 possibilities:
- run command without going into background (
&), read the password from standard input instead of the terminal device by
sudo -Se.g.echo mypass | sudo emacs tet.cconfigure sudo to not ask for the password by:
visudocommand and editingsudoersfile. See: EnableNOPASSWDfor user
When you encounter there are stopped jobs error:
- type
jobs--> you will see the jobs with stopped status - and then type
exit--> you can get out of the terminal
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"