-5

Bash manual says

logout [n]

Exit a login shell, returning a status of n to the shell’s parent.

On a virtual console of Ubuntu, I first log in, and in the login shell, run:

$ pstree -paus $$
systemd,1 --system --deserialize 19
  `-login,30488 -p --  
      `-bash,31728,t
          `-pstree,31774 -paus 31728

and then run logout, and all the processes starting from login,30488 till below disappear, more than just "return to the shell's parent" which is thelogin process.

In a login bash shell , does bash builtin commandlogout log out of the OS, not just exit the shell?

Does exiting a login shell (not necessarily by logout, but also any other way, such as bash builtin exit among others) necessarily lead to logging out of the OS?

May I also ask what logging out of OS means?

Thanks.


Extended to: https://stackoverflow.com/questions/53887813/how-does-the-login-program-in-linux-invoke-a-login-shell

2

In bash speak, "login shell" means a shell invoked with the -l flag, or where the first character of argument 0 begins with a -. (See man bash INVOCATION section).

In your example, you can see process 31728 is called -bash, so begins with a - and so was invoked as a login shell.

logout simply exits a login shell.

So if you run bash -l and then logout you'll find yourself back at the calling shell.

$ echo $$
32145
$ bash -l
bash-4.2$ logout
$ echo $$
32145

Now the login program (process 30488 in your example) waits for the child shell to exit, then performs some cleanup actions (eg wtmp, utmp) then exits. That is why you no longer see this process after running logout.

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.