0 votes
94 views
in Linux by

What is SIGINT and how do you handle it on the command line?

1 Answer

0 votes
by

A SIGINT signal is a type of signal that is sent to a process to interrupt its execution. In Linux, a SIGINT signal is generated when the user presses the "CTRL+C" key combination.

To handle a SIGINT signal on the command line in Linux, you can use the "trap" command. The "trap" command allows you to specify a command or series of commands that should be executed when a specific signal is received. For example, to handle a SIGINT signal and exit gracefully, you can use the following command:

trap "echo Exiting...; exit" SIGINT
This command will print the message "Exiting..." and then exit the process when a SIGINT signal is received. You can also use the "trap" command to ignore the SIGINT signal and continue running the process, or to execute any other desired commands when the signal is received.

...