0
0
Bash Scriptingscripting~10 mins

Signal handling with trap in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to catch the SIGINT signal and run the cleanup function.

Bash Scripting
trap cleanup [1]
Drag options to blanks, or click blank then click option'
ASIGKILL
BSIGINT
CSIGTERM
DSIGSTOP
Attempts:
3 left
💡 Hint
Common Mistakes
Using SIGKILL or SIGSTOP which cannot be trapped.
Confusing SIGTERM with SIGINT.
2fill in blank
medium

Complete the code to ignore the SIGTERM signal.

Bash Scripting
trap '' [1]
Drag options to blanks, or click blank then click option'
ASIGTERM
BSIGHUP
CSIGQUIT
DSIGINT
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to ignore SIGINT instead of SIGTERM.
Using an invalid signal name.
3fill in blank
hard

Fix the error in the trap command to correctly catch SIGQUIT and run the quit_handler function.

Bash Scripting
trap [1] SIGQUIT
Drag options to blanks, or click blank then click option'
Aquit_handler;
Bquit_handler &
Cquit_handler()
Dquit_handler
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after the function name.
Adding extra characters like '&' or ';' after the function name.
4fill in blank
hard

Fill both blanks to run cleanup on SIGINT and SIGTERM signals.

Bash Scripting
trap cleanup [1] [2]
Drag options to blanks, or click blank then click option'
ASIGINT
BSIGTERM
CSIGKILL
DSIGSTOP
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to trap SIGKILL or SIGSTOP which cannot be caught.
Using wrong signal names.
5fill in blank
hard

Fill all three blanks to create a trap that runs handle_exit on EXIT and SIGINT.

Bash Scripting
trap [1] [2] [3]
Drag options to blanks, or click blank then click option'
Ahandle_exit
BEXIT
CSIGINT
DSIGTERM
Attempts:
3 left
💡 Hint
Common Mistakes
Putting signals before the function name.
Using parentheses with the function name.