Complete the code to listen for the SIGINT signal and log a message.
Deno.addSignalListener([1], () => { console.log("Received SIGINT, exiting..."); Deno.exit(); });
The "SIGINT" signal is sent when you press Ctrl+C. Listening to it allows graceful shutdown.
Complete the code to spawn a subprocess that runs the 'echo' command.
const process = Deno.run({
cmd: ["echo", [1]],
stdout: "piped"
});The command arguments must be strings. So the message should be in quotes.
Fix the error in the code to correctly wait for the subprocess to finish.
const process = Deno.run({ cmd: ["ls"], stdout: "piped" });
const status = await process.[1]();
process.close();The correct method to wait for a subprocess to finish is wait().
Fill both blanks to create a signal listener that stops the process on SIGTERM and logs a message.
Deno.addSignalListener([1], () => { console.log("[2] received, stopping process."); Deno.exit(); });
The signal name must be a string like "SIGTERM". The message can be any string describing the event.
Fill all three blanks to spawn a subprocess that runs 'cat' on a file, waits for it, and closes it.
const process = Deno.run({ cmd: [[1], [2]], stdout: "piped" });
const status = await process.[3]();
process.close();The command is "cat", the argument is the filename "file.txt", and the method to wait is wait().
