-1

I always felt that in shell scripting in general and in Bash in particular, the terms "session" and "process" usually mean the exact same thing as an execution of some codepiece, that either has to do with the the kernel/shell/some-utility.

Are the terms session and process totally synonymous in shell-scripting or at least in Bash?

  • Yes, I just hinted that you could mention this in an answer, if you want... –  Sep 30 '18 at 18:14
  • I recommend reading existing questions on the subject first, such as https://unix.stackexchange.com/questions/82844/ , https://unix.stackexchange.com/questions/441999/ , https://unix.stackexchange.com/questions/331585/ , and https://unix.stackexchange.com/questions/405755/ just for starters. – JdeBP Sep 30 '18 at 23:34
  • "session" and "process" are NOT synonymous. Even if a session has just a process in it, the session's lifetime not tied to the lifetime of the process; the process could fork, then exit, and it would stilll be the session leader (the process whose session id is equal to its pid) even after death, as long as there are still processes with the same session id around. –  Oct 01 '18 at 00:53

1 Answers1

3

Are the terms session and process totally synonymous in shell-scripting or at least in Bash?

No, they're not the same at all.

A process is a running instance of a program. It has a process id (PID), a set of virtual memory, a user id, a set of open file descriptors, and a number of other things.

The Unix concept of a session is a kernel construct related to grouping processes mostly in the context of a terminal-based login.

A session is a group of processes, itself divided to one or more process groups. The following diagram from Advanced Programming in the Unix Environment shows the relations quite well:

enter image description here

It should be mentioned that the session as a whole can have a controlling terminal, but the processes within it are otherwise distinct.

See:


Notes:

  • Of course, "session" can have other meanings not related to terminals. The concept of a login session can make sense in a GUI system or e.g. a Web-based program too, even if they didn't use terminals and process groups in the same way as a terminal-based session.

  • Then again, "process" has other less technical meanings too.

ilkkachu
  • 138,973