Multiple choice technology operating systems

Which of the following would return the process ID of the sleep command?

  1. test sleep 1

  2. sleep 1 && echo $0
  3. sleep 1 & echo $!
  4. sleep 1 & echo $$
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In shell, $! returns the PID of the last background process. Option C correctly backgrounds sleep with & then echoes $!. Option D's $$ is the current shell's PID, and $0 in B is the shell name, not the background process.