Podcast
Questions and Answers
What command is used to remove an environment variable?
What command is used to remove an environment variable?
Which environment variable holds the default path to the user's home directory?
Which environment variable holds the default path to the user's home directory?
What does the PATH environment variable do?
What does the PATH environment variable do?
Which command will delete the variable 'new_variable'?
Which command will delete the variable 'new_variable'?
Signup and view all the answers
Which environment variable contains the path to the default shell the user is utilizing?
Which environment variable contains the path to the default shell the user is utilizing?
Signup and view all the answers
Match the Bash variable with its description:
Match the Bash variable with its description:
Signup and view all the answers
Match the special character in PS1 with its function:
Match the special character in PS1 with its function:
Signup and view all the answers
Match the command with its purpose:
Match the command with its purpose:
Signup and view all the answers
Match the PS2 prompt function with its description:
Match the PS2 prompt function with its description:
Signup and view all the answers
Match the action with its result:
Match the action with its result:
Signup and view all the answers
Study Notes
Process Management in Shell
- A process can have three statuses: foreground, background, or stopped (suspended).
- Only one job can be in the foreground at a time, receiving keyboard input and sending output to the screen.
- Background jobs run quietly without terminal input and require user attention only if they need interaction.
- Jobs can be suspended using Ctrl-Z; suspended jobs can continue running in the foreground with fg or in the background with bg.
- Interrupting a job with Ctrl-C kills it permanently, unlike suspending which allows resuming.
- To run a command in the background, append an '&' to the command line.
- Shell returns the job number and PID of the background process for management.
Job Control Commands
- ps lists processes and their details, including PIDs.
- kill can terminate processes using either PID or job ID.
- Use kill -9 to forcefully kill a process with a higher success probability.
- Commands for job control:
- jobs: List all current jobs.
- bg: Resume a stopped job in the background.
- fg: Resume a stopped job in the foreground.
- stop: Stop execution of a job.
Shell Variables
- Shell variables are typically set when a new shell is initiated.
- Environmental variables (global) are accessible in all shells; can be viewed using env or printenv.
- Local variables are accessible only in the current shell; view using set.
- Use echo $VARIABLE_NAME to retrieve the value of a shell variable.
- Variables can be defined using the syntax
VAR_NAME=value
.
Bash Configuration Variables
- PS1 controls the appearance of the shell prompt.
- Special characters in PS1:
- \u: Username
- \h: Hostname
- \w: Current working directory
- To change an environment variable, use
export VARIABLE=VALUE
. - PATH: Contains directories for executable file searches, separated by colons.
- Modifying PS1 can customize the command line prompt to include additional information like date and time.
Removing Environment Variables
- Use the unset command to remove an environment variable completely.
Common Environment Variables
- PATH: Directories for file search.
- USER: Current user’s username.
- HOME: Path to the user’s home directory.
- EDITOR: Path to the default text editor.
- UID: User's unique ID.
- TERM: Default terminal emulator path.
- SHELL: Path to the default shell.
- ENV: Displays all environment variables.
Process Management
-
A process is defined as a program in execution, created when a command is invoked from a shell.
-
Each process is identified by a unique Process Identifier (PID).
-
The init process is a vital process that is always running in Linux.
-
Types of processes include:
- Interactive processes
- Automatic processes
- Daemons
-
The ps command displays process information, with options to show various process attributes.
-
Example usage of the ps command displays current shell processes with their PIDs.
Controlling Processes
- Job control allows management of multiple processes in the shell.
- Processes can be in one of three statuses:
- Foreground: interacts with the user via keyboard and screen.
- Background: runs without user input.
- Stopped: temporarily suspended.
- Use Ctrl-Z to suspend a foreground process and resume it with fg (foreground) or bg (background).
- Ctrl-C sends an interrupt to terminate a foreground job, unlike suspending.
Job Control Commands
- kill command terminates a job using its PID or job number.
- The jobs command lists jobs associated with the current shell.
- & runs commands in the background.
- Other job control commands:
- bg: Resume a stopped job in the background.
- fg: Resume a stopped job in the foreground.
- stop: Stop the execution of a job.
Shell Variables
- Shell variables typically use uppercase characters and can be defined using single or double quotes for strings.
- Double quotes allow variable resolution, whereas single quotes do not.
- Use the export command to make a local variable available as an environment variable for child processes.
Environment Variables
- PATH variable specifies directories for the shell to search for executables, separated by colons.
- The PS1 variable defines the format of the shell prompt, comprising components like username (\u), hostname (\h), and current working directory (\W).
- Changing the Prompt: Modify PS1 to adjust prompt details; special characters can customize prompt appearances.
Modifying Environment Variables
- Set environment variables with export VARIABLE=VALUE.
- To see a variable's value, use echo $VARIABLE.
- To add directories to the PATH, you can append them using:
- export PATH="$PATH:/new/directory".
- Remove an environment variable to eliminate its current value and associated components.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the different statuses of processes in an operating system, specifically focusing on foreground, background, and stopped statuses. Learn about how these statuses affect job control and interaction within a shell environment.