




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





In Linux, all user-space processes are spawned from another process, (with the exception of the very first processes created by the kernel at boot time.)
All child processes inherit a context automatically from their parent processes. This includes:
Category Inherited Items
Identity & Security Real UID, Effective UID, Saved UID, Real GID, Effective GID, Saved GID, Supplementary groups, Capabilities, Security context (SELinux/AppArmor)
Execution Environment
Environment variables, Locale settings, Umask
Filesystem Context Current working directory (CWD), Root directory (chroot), Open file descriptors, File descriptor flags (e.g. FD_CLOEXEC), Memory-mapped files (inheritable) Signal State Signal dispositions (handlers / ignored / default), Signal mask Resource & Scheduling
Resource limits (rlimit), Nice value, Scheduling policy / priority Process Relationships
Parent PID (PPID), Process group ID (PGID), Session ID (SID), Controlling terminal
IPC & Shared State Pipes, Sockets, Message queues, Shared memory mappings
Runtime / Kernel State
Address space (copy-on-write), Thread state (if multithreaded)
The shell is essentially a process, and all that spawns from it whether programs or instances of the shell itself, are its child processes. Like all other processes the shell too passes down the process context discussed above, to its child processes.
Along with the process context, in the case of shells, there is another category of objects: the āshell configurationā including aliases, functions and variables.
This category is not automatically inherited by child processes, unlike process context. It is obtained by sourcing files where these objects are defined like .bashrc. Informally, all of this is bundled together and imprecisely termed: the shell environment. To be precise, we will distinguish between the two:
Shell Context
Process context
Environment variables, CWD, file descriptors, UID, GID ā¦. and much more
Shell configuration
Aliases, functions, shell variables (those not exported).
There are five kinds of objects that constitute the user-defined command context in Linux.
Aliases
Variables (shell variables, environment variables)
Shell functions
Scripts (āshell scriptsā, if the interpreter is the shell itself)
Programs (those that are compiled before execution.)
Aliases :
Alises function as macro text replacement. Their primary usage is to replace a long string of commands (or a single long command) with a short string.
Aliases canāt take arguments.
Inclusion method Availability
Defining aliases in a file, then sourcing the file.
Available in whichever shell sources the file.
Inclusion method Availability
Defining variables in a file, then sourcing the file.
Available in the shell which sources the file.
defining and exporting variables in a file, then sourcing the file.
Available in the shell which sources the file and all its child processes.
A bunch of commands strung together, the procedure given a name. The entire sequence of commands can be invoked using the name. This can take arguments, unlike aliases.
Inclusion method Availability
Defining functions in a file, then sourcing the file.
Available in the shell which sources the file.
defining and exporting functions in a file, then sourcing the file. (fragile, NOT recommended)
Available in the shell which sources the file and all its child processes.
Note : A script run as ./script.sh is a child process. However, commands run in parentheses (command) are subshells. They are clones of the current shell (including non-exported variables) but still cannot modify the parent.
NOTE : aliases, variables, shell functions and scripts could also be just typed in the command line interactively. This is what sourcing results in anyway. But that is not a sane practice. Usually you just put the most used objects in a file and add a command to source them (or source the files containing them) in your config files like .bashrc.
Type Aliases Shell functions Scripts Programs description Basic text replacement. Used to replace long sequence of commands with a short string. Canāt
Sequence of commands which can take arguments; defined in a file
Sequence of commands which can take arguments; put in a file.
Sequence of commands which can take arguments; need to be compiled before
take arguments. execution. Method of inclusion/ execution
Source file which contains definition
Source file which contains definition
Always available via path. Either execute directly or source.
Always available via path, executed directly, canāt be sourced Shell session
Current shell Current shell Child process if executed directly, current shell if sourced.
As a separate process always
Misc ā the exec command allows a program to replace the current shell process (keeping the same PID) instead of spawning a child. This is the only way a program runs without being a "child."