As you may know, you can use the shortcut Ctrl + C in the console to terminate a process running in the foreground. It interrupts the current foreground process by sending the SIGINT signal to the process. Basically, this is just a request to stop the current process. What is very good about it is that you can also intercept and process this signal using PHP. Let's take a look how you can integrate it in your own console command:

<?php
public function handle()
{
    // Do some stuff in your command
    // Catch the cancellation (Ctrl+C)
    pcntl_async_signals(true);
    pcntl_signal(SIGINT, function () use ($master) {
        $this->line('You pressed Ctrl + C');
    });
}