Linux and Command-Line Basics

While a long-running ./sim.sh is running in a terminal, you want to use other commands in the same terminal. Which of the following is what happens when you press Ctrl+Z and then run bg?

  1. ACtrl+Z ends sim.sh, and running bg starts the same command again from the beginning in the background
  2. BCtrl+Z suspends sim.sh, and bg resumes it from where it stopped, in the background
  3. CCtrl+Z moves sim.sh to the background where it keeps running, and running bg suspends it
Show answer and explanation

Answer: B. Ctrl+Z suspends sim.sh, and bg resumes it from where it stopped, in the background

Pressing Ctrl+Z sends SIGTSTP to the job running in the foreground, and the job is suspended. bg tells that job to resume and continue in the background, and fg brings it back to the foreground. The jobs and their states can be checked with jobs, and to run something in the background from the start, it is launched with &, as in "./sim.sh &". However, background jobs may also stop when the terminal connection is lost, so long-running work needs a separate measure.

  • A. Ctrl+Z suspends the job rather than ending it. bg resumes it from where it stopped, not from the beginning.
  • B. Correct. bg resumes the suspended job in the background.
  • C. The roles of Ctrl+Z and bg are reversed. Ctrl+Z suspends, and bg resumes in the background.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. On a server reached over SSH, a long-running task was started with "./run.sh &", and when the connection was closed the task stopped too. Which of the following is the most appropriate way to start it so that it keeps running after the connection is closed?
  2. When the two lines above are run in a shell, which of the following are the characters shown?
  3. When the commands above are run in order, which of the following is the output of the two echo commands?
  4. As shown above, the script s.sh is run with arguments. Which of the following is the output?
  5. In a shell script, in which of the following cases is the condition of the if above true?