Bash - Bash Own process

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU) > Bash - Bash Own process

1 - About

This article is about the bash Process.

To see how to manage another general linux process, see Linux - Process

Advertising

3 - Process

3.1 - Interactive

  • The process running the command is created.
  • The process inherits the stdin, stdout, and stderr from the shell. Because it inherits stdin, it stay connected to the same terminal.
  • If the shell receives a SIGHUP, it also sends a SIGHUP to the process (which normally causes the process to terminate).
  • Otherwise the shell waits (is blocked) until the process terminates.

3.2 - Non-Interactive

  • & puts the job in the background: ie
    • it block on attempting to read input,
    • and makes the shell not wait for its completion.
    • removes the process from the shell's job control,
    • leaves the process connected to the terminal. The shell won't send it a SIGHUP. Obviously, it can only be applied to background jobs, because you cannot enter it when a foreground job is running.
    • disconnects the process from the terminal,
    • redirects its output to nohup.out
    • shields the process from SIGHUP. One of the effects (the naming one) is that the process won't receive any sent NOHUP. It is completely independent from job control and could in principle be used also for foreground jobs (although that's not very useful).
Advertising

4 - Builtin Stop

Advertising

5 - Management

5.1 - Environment variable

5.1.1 - $$

From the bash man page: $ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the sub-shell.

echo $$

The $$ variable often finds use in scripts to construct “unique” temp file names

5.1.2 - BASHPID

BASHPID: Process ID of the current instance of Bash. <warning>bash 4</wrap>

echo $BASHPID

5.1.3 - $PPID

The $PPID of a process is the process ID (pid) of its parent process.

5.1.4 - $!

The PID (process ID) of last job run in background

6 - Documentation / Reference