To terminate an ongoing process in a Unix-like operating system (like Linux or macOS), you can use several methods, depending on how the process was started and the environment you are working in.
Methods to Terminate a Process:
1. Using `Ctrl+C`:
- This is the most common way to terminate a process running in the foreground in a terminal. It sends a SIGINT (Signal Interrupt) to the process, which causes it to terminate.
2. Using `kill` command:
- You can use the `kill` command to send a signal to a process, usually to terminate it.
- First, find the Process ID (PID) using the `ps` or `top` command, then use `kill`:
\[
kill PID
\]
- To forcefully terminate a process, use:
\[
kill -9 PID
\]
3. Using `killall` command:
- If you want to terminate all processes with a particular name, you can use the `killall` command:
\[
\text{kill all process\_name}
\]
4. Using `htop` or `top`:
- In more advanced systems, you can use `htop` (a more interactive process viewer) to kill processes. Select the process and press F9 to kill it.
Example:
To terminate a process with PID 1234:
\[
\texttt{kill 1234}
\]
To forcefully kill the same process:
\[
\texttt{kill -9 1234}
\]