Challenge - 5 Problems
Signal Mastery in Deno
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat happens when a Deno process receives a SIGINT signal?
Consider this Deno script that listens for the SIGINT signal (Ctrl+C). What will be printed when you press Ctrl+C during its execution?
Deno
Deno.addSignalListener("SIGINT", () => { console.log("Signal SIGINT received, cleaning up..."); Deno.exit(0); }); console.log("Process running. Press Ctrl+C to stop."); setInterval(() => {}, 1000);
Attempts:
2 left
💡 Hint
Think about what Deno.addSignalListener does when a signal is caught.
✗ Incorrect
When the SIGINT signal is received (usually by pressing Ctrl+C), the listener runs the callback, prints the message, and calls Deno.exit(0) to stop the process cleanly.
📝 Syntax
intermediateWhich code snippet correctly spawns a child process in Deno?
You want to run the command `echo Hello` as a child process in Deno. Which snippet correctly does this and prints the output?
Attempts:
2 left
💡 Hint
Check the correct method name and property names for spawning processes in Deno.
✗ Incorrect
Deno.run is the correct method to spawn a child process with the cmd array. The output is a Uint8Array and needs decoding. Options B and D use a non-existent method 'spawn'. Option A uses 'command' instead of 'cmd', which is invalid.
🔧 Debug
advancedWhy does this Deno script not exit after receiving SIGTERM?
This script listens for SIGTERM but does not exit as expected. What is the reason?
Deno
Deno.addSignalListener("SIGTERM", () => { console.log("SIGTERM received"); }); console.log("Waiting for SIGTERM..."); setInterval(() => {}, 1000);
Attempts:
2 left
💡 Hint
Think about what happens after the signal listener runs.
✗ Incorrect
The listener prints the message but does not stop the process. Without calling Deno.exit(), the process keeps running the empty interval loop.
❓ state_output
advancedWhat is the output of this Deno script managing multiple signals?
Analyze the output when this script receives SIGINT and then SIGTERM signals in order.
Deno
let sigintCount = 0; let sigtermCount = 0; Deno.addSignalListener("SIGINT", () => { sigintCount++; console.log(`SIGINT count: ${sigintCount}`); if (sigintCount >= 2) Deno.exit(0); }); Deno.addSignalListener("SIGTERM", () => { sigtermCount++; console.log(`SIGTERM count: ${sigtermCount}`); }); console.log("Process started. Send signals now."); setInterval(() => {}, 1000);
Attempts:
2 left
💡 Hint
Count how many times each signal handler runs and when exit is called.
✗ Incorrect
The SIGINT handler increments count and exits only after the second SIGINT. SIGTERM handler just increments count and logs. So the output matches option A.
🧠 Conceptual
expertWhich statement about Deno signal handling and process management is true?
Select the one true statement about how Deno handles signals and child processes.
Attempts:
2 left
💡 Hint
Consider how signal listeners affect process lifecycle and exit.
✗ Incorrect
Signal listeners run asynchronously and the process continues unless Deno.exit() is called. Deno does not automatically kill child processes; signal handling is built-in without extra imports; SIGTERM is supported on Unix platforms.
