82

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?

3 Answers 3

105

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.

2
27

You 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 of bg for background),
  • run disown to 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/logout twice,
  • kill these jobs manually by running: kill $(jobs -p) (add -9 for 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 -S e.g.

    echo mypass | sudo emacs tet.c
    
  • configure sudo to not ask for the password by: visudo command and editing sudoers file. See: Enable NOPASSWD for user

11

When you encounter there are stopped jobs error:

  1. typejobs--> you will see the jobs with stopped status
  2. and then type exit--> you can get out of the terminal
1
  • Thank you, "jobs" is what I was looking for.
    – TheTC
    Nov 6, 2020 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .