Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following commands would return process_id of sleep command ?

  • A.Sleep 1 and echo $?
  • B.Sleep 1 and echo $#
  • C.Sleep 1 and echo $×
  • D.Sleep 1 and echo $!

Answer: D

The command that returns the process id of a background sleep command is "Sleep 1 and echo $!" (the shell variable $! holds the process id of the most recently started background command). The ampersand, which the printed text spells as "and", puts sleep in the background.

The variable $? gives the exit status of the last command, $# gives the number of positional parameters, and the printed $ with a multiplication sign is not the process id variable. Only $! gives the id of the background process.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.