Process Management with Bash: Jobs, Signals, and Scheduling Quiz Quiz

Explore essential concepts of process management in Bash, including background jobs, signals, and job scheduling. This quiz is designed to reinforce your understanding of Bash commands and techniques for effective process control and job handling.

  1. Identifying Background Jobs

    Which Bash symbol allows you to run a process in the background, as seen in the command sleep 60 u0026?

    1. $
    2. *
    3. u0026
    4. #

    Explanation: The ampersand 'u0026' placed at the end of a bash command sends the process to run in the background, letting you continue using the terminal. The hash symbol '#' is used for comments in Bash scripts and does not affect job control. The dollar sign '$' denotes variables or shell prompts, while the asterisk '*' is a wildcard character. Only 'u0026' initiates a background process.

  2. Bringing Jobs to Foreground

    If you have a background job with job number 1, which Bash command brings it to the foreground?

    1. run %1
    2. fg %1
    3. bg 1
    4. kill 1

    Explanation: The 'fg %1' command brings the background job with job number 1 to the foreground, allowing it to receive input. The 'bg' command resumes jobs in the background, 'kill' terminates a process, and 'run' is not a Bash command for job control. Only 'fg %1' correctly moves the job to the foreground.

  3. Listing Active Jobs

    What Bash command displays your currently running jobs and their statuses in the terminal?

    1. list
    2. ps
    3. show
    4. jobs

    Explanation: 'jobs' lists all background and stopped jobs started from the current shell, showing their status. 'ps' shows processes for the whole system or a user but not specifically jobs related to your shell. 'show' and 'list' are not valid Bash commands for this task. Therefore, 'jobs' is the correct answer.

  4. Sending a Signal to a Process

    Which command is commonly used in Bash to send a signal, like SIGTERM, to a running process by its process ID (PID)?

    1. terminate
    2. kill
    3. signal
    4. end

    Explanation: The 'kill' command sends signals to processes identified by their PID, such as sending a SIGTERM to stop them gracefully. 'Terminate', 'signal', and 'end' might sound relevant but are not default Bash commands for this function. Only 'kill' is the correct built-in tool for signaling processes by PID.

  5. Using nohup for Terminal Sessions

    What is the purpose of using 'nohup' before a command, as in nohup python myscript.py u0026?

    1. Runs the process with higher priority
    2. Shows process output in a new terminal window
    3. Prevents process termination when terminal closes
    4. Adds the process to the crontab

    Explanation: 'nohup' allows a command to continue running after you log out or close the terminal, protecting it from SIGHUP signals. It does not increase process priority (which is done with 'nice') and does not create a new terminal window or schedule tasks (which is achieved with 'crontab'). Only the first option accurately describes 'nohup's' purpose.

  6. Understanding the bg Command

    If you have stopped a job with Ctrl+Z, how can you resume it in the background using Bash?

    1. continue
    2. run-bg
    3. resume
    4. bg

    Explanation: The 'bg' command resumes a stopped job in the background so you can continue using the terminal. 'Resume', 'continue', and 'run-bg' are not standard Bash job control commands; they will result in errors. Therefore, 'bg' is the only correct and effective option.

  7. Scheduling One-Time Commands

    Which Bash command schedules a one-time execution of a command such as echo 'Backup Complete' at a specified time?

    1. later
    2. timer
    3. at
    4. cron

    Explanation: The 'at' command is used to schedule a one-time task at a specific time. 'Cron' schedules recurring tasks with crontab, 'later' and 'timer' are not default Bash tools for scheduling. Only 'at' can carry out a single, scheduled execution.

  8. Job Numbers vs. Process IDs

    In Bash, which character is used to refer to a job by its job number, such as %2 to refer to job number 2?

    1. u0026
    2. %
    3. $
    4. #

    Explanation: The percent symbol '%' is used to refer to jobs by their job numbers in Bash, like '%2' for job 2. The hash '#' is for comments, 'u0026' runs tasks in the background, and '$' relates to variables or commands. Only '%' appropriately references job numbers in job control commands.

  9. Common Signal for Graceful Termination

    What signal does 'kill' send by default to a process if no signal is specified, aiming for graceful termination?

    1. SIGSTOP
    2. SIGCONT
    3. SIGKILL
    4. SIGTERM

    Explanation: 'SIGTERM' is the default signal sent by 'kill', allowing a process to clean up before ending. 'SIGKILL' forces an immediate stop without cleanup, 'SIGSTOP' stops (pauses) the process, and 'SIGCONT' resumes a stopped process. Only 'SIGTERM' is sent by default and allows for graceful termination.

  10. Viewing Process Details

    Which Bash command displays detailed information about all running processes on the system?

    1. list -all
    2. showall
    3. jobs
    4. ps aux

    Explanation: 'ps aux' provides a comprehensive list of all system processes, displaying extensive details. The 'jobs' command only shows jobs in the current shell session, 'showall' and 'list -all' are not valid Bash commands. Thus, 'ps aux' is the correct way to view all running processes.