'How to end a hardhat node so that the associated PID is freed?

After I run a node for example:

npx hardhat node

I want to end the node and free the port so I can run another node something like:

npx hardhat node --fork <mainnet_link>

Currently, I do ctrl+z and the use lsof -i :8545 to get the PID of the port and then do kill -9 PID to free up the port otherwise I get a EADDRINUSE error.

Is there anyway to kill the port from the node instead of doing ctrl+z?

EDIT: Ctrl+C



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source