5

I have just installed SLC6 (derived from SL6 derived from RHEL6). I can send a running process to the background by hitting Ctrl-Z in the terminal where it was started. However, I can't do it when I started the command with sudo. It used to work seamlessly in SLC5.

Is there any configuration I could do to allow this ?

EDIT This is an example of command I try to run :

[user@pcald02 ~]$ sudo emacs
^Z^C

The Ctrl-Z makes the symbols ^Z appear but nothing else happens. Now I realized that even Ctrl-C is ineffective.

Without sudo :

[user@pcald02 ~]$ emacs
^Z
[1]+  Stopped                 emacs
[user@pcald02 ~]$ 
  • 1
    Since slm says it works for him on RHEL/CentOS6, you might want to update the post with the actual command that you're trying to run, in case it's something specific to that one command. – Bratchley Jul 2 '13 at 15:58
  • For a new command, instead of an existing command, sudo -b might do what you want... (It does not work if you want to reattach though... For that screen might be the best option...) – Gert van den Berg Nov 2 '16 at 9:33
2

I'm guessing the real problem here is that the command you are trying to run is Emacs. Running Emacs as root is hardly ever a good idea. Emacs also overrides a number of keystrokes, so C-z might not work simply for that reason. If root is already logged in, emacs might start graphically on root's display. Etc, etc.

Look at using the sudo: method from Tramp for editing files using sudo from Emacs. For example, to edit /etc/motd, do C-x C-f and type the path as /sudo:root@localhost:/etc/motd.

5

If I'm understanding your question the following worked just fine for me on CentOS 6.4 which I would expect to be very similar to SLC6:

initital command
$ sudo sleep 300
^Z
[1]+  Stopped                 sudo sleep 300
background
$ bg
[1]+ sudo sleep 300 &

$ jobs
[1]+  Running                 sudo sleep 300 &

$ ps -eaf|grep sudo
root     25752 25669  0 09:53 pts/0    00:00:00 sudo sleep 300
sam      25755 25669  0 09:53 pts/0    00:00:00 grep sudo
kill job (Ctrl+C)
$ fg
sudo sleep 300
^C

$ ps -eaf|grep sudo
sam      25758 25669  0 09:53 pts/0    00:00:00 grep sudo
OS Info
$ uname -a
Linux mungr 2.6.32-358.6.1.el6.x86_64 #1 SMP Tue Apr 23 19:29:00 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release 
CentOS release 6.4 (Final)
  • What is strange is that the ^Z after the initial command does nothing. – Barth Jul 2 '13 at 15:27
4

CTRL-Z sends signal SIGTSTP to the process.

So the simplest way to do this is:

sudo kill -TSTP <pid>

from another shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.