Process Status in Operating Systems
10 Questions
0 Views

Process Status in Operating Systems

Created by
@StylishSpessartine

Questions and Answers

What command is used to remove an environment variable?

  • remove
  • delete
  • unset (correct)
  • clear
  • Which environment variable holds the default path to the user's home directory?

  • SHELL
  • HOME (correct)
  • USER
  • PATH
  • What does the PATH environment variable do?

  • Indicates the unique user ID
  • Specifies the default terminal emulator
  • Stores directory locations for file searching (correct)
  • Holds user information
  • Which command will delete the variable 'new_variable'?

    <p>unset new_variable</p> Signup and view all the answers

    Which environment variable contains the path to the default shell the user is utilizing?

    <p>SHELL</p> Signup and view all the answers

    Match the Bash variable with its description:

    <p>PS1 = Specifies the shell prompt display PATH = Holds directory paths for executable programs USER = Contains the user's login name HOSTNAME = Identifies the machine's hostname</p> Signup and view all the answers

    Match the special character in PS1 with its function:

    <p>\u = Displays the username \h = Displays the hostname \w = Shows the current working directory $ = Indicates whether the user is normal or root</p> Signup and view all the answers

    Match the command with its purpose:

    <p>echo $VARIABLE = Displays the current value of a variable export VARIABLE=VALUE = Sets the value of an environment variable export PATH=&quot;$PATH:/usr/local/bin:/usr/games&quot; = Adds directories to the PATH variable export PS1=':\w$ ' = Changes the shell prompt format</p> Signup and view all the answers

    Match the PS2 prompt function with its description:

    <p>PS2 = Alternative prompt for incomplete commands PS1 = Main prompt displayed in the shell \t = Displays the current time \d = Displays the current date</p> Signup and view all the answers

    Match the action with its result:

    <p>Removing an environment variable = Eliminates all components of that variable Changing PS1 = Alters how the shell prompt appears Viewing $PATH = Shows the paths where executables are searched Using export = Sets or modifies the value of a variable</p> 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.

    Quiz Team

    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.

    More Quizzes Like This

    Operating System Concepts - Process Management
    10 questions
    Operating Systems Process Management
    14 questions
    Operating Systems: Process Management
    13 questions
    Use Quizgecko on...
    Browser
    Browser