Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

if I ps aux | grep su I currently have the following after switching users a few times:

fmaster  24811  0.0  1.3  10652  7000 pts/3    S    23:11   0:00 -su
root     24932  0.0  0.2   5352  1464 pts/3    S    23:12   0:00 su - root
root     24941  0.0  0.8   7772  4256 pts/3    S    23:12   0:00 -su
fmaster  27148  0.0  0.2   5352  1436 pts/3    S    23:28   0:00 su - fmaster
fmaster  27155  0.0  1.3  10652  7044 pts/3    S    23:28   0:00 -su
root     27284  0.0  0.2   5352  1468 pts/3    S    23:29   0:00 su -
root     27293  0.0  0.8   7732  4208 pts/3    S    23:29   0:00 -su
fmaster  27685  0.0  0.2   5352  1424 pts/3    S    23:32   0:00 su - fmaster
fmaster  27692  0.0  1.3  10652  7060 pts/3    S    23:32   0:00 -su
root     27842  0.0  0.2   5352  1468 pts/3    S    23:32   0:00 su -
root     27853  0.0  0.8   7748  4244 pts/3    S    23:32   0:00 -su
fmaster  29407  0.0  0.2   5352  1432 pts/3    S    23:41   0:00 su - fmaster
fmaster  29414  0.0  1.4  10656  7152 pts/3    S    23:41   0:00 -su
root     29846  0.0  0.2   5352  1468 pts/3    S    23:44   0:00 su -
root     29853  0.0  0.8   7700  4156 pts/3    S    23:44   0:00 -su
fmaster  30008  0.0  0.2   5352  1436 pts/3    S    23:45   0:00 su - fmaster
fmaster  30015  0.0  1.3  10652  7124 pts/3    S    23:45   0:00 -su
root     30180  0.0  0.2   5352  1468 pts/3    S    23:46   0:00 su -
root     30189  0.0  0.8   7744  4244 pts/3    S    23:46   0:00 -su

do these processes get cleaned up automatically? or do I have to manually kill them?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

There's a command for just this occasion: killall

killall su
share|improve this answer
    
is this dangerous? also why do these accumulate? –  tester Mar 14 '12 at 7:19
1  
Any command can be dangerous in the right context. Each su is like opening a new session as the given user. If you su user, but never exit to return to the original user, you've created a deeply-nested series of shells. Think Inception, but with bash. –  Joel E Salas Mar 14 '12 at 7:50

When you are "switching users" you are actually spawning a new shell as that user. Your old shell still exists and is the parent of your current shell. Think of it like building a new cardboard box to play in and putting it inside your existing cardboard box and then jumping inside it.

If you "switch users" from root to fmaster and back to root again, you will now have three shells running, each the parent of the next. Do this ten times and you now have 11 shells running. These are all taking up memory and CPU but otherwise they are doing no harm.

If you have it installed, you can see all of these shells chained together with the command pstree. If not, you can use ps -ejH or ps -axjf.

They will all end when you disconnect from the server.

The killall command suggested by Joel will have a similar effect but it's a strange way of doing things. For starters, if you are currently running in a shell with the permissions of fmaster, only the fmaster shells will be killed. i.e every second one. However, since all the root shells will now have both their parent and their only child killed, they will also terminate. If you run the killall command as root, all of them will be killed. Either way, this will unceremoniously dump you out of all the subshells and back into your original login shell.

You can end your current shell and drop back to the previous one by typing either exit, logout or ctrl-d.

Unless you have a specific need to be running a shell as root, you're usually better off using sudo in front of any commands you want to run with root permissions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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