Starting a process:
1. Executing a command in the foreground:
- To start a process and execute a command in the foreground, open a terminal and simply type the desired command. For example, to list files and directories in the current directory, you can use the `ls` command: `ls`.
- The process will start executing, and you'll see the output directly in the terminal. You won't be able to use the terminal for other commands until the process finishes or you terminate it.
2. Executing a command in the background:
- If you want a process to run in the background, allowing you to continue using the terminal for other commands, you can append an ampersand (`&`) to the command. For example, to start the Firefox web browser in the background, you can use: `firefox &`.
- The process will start in the background, and you'll regain control of the terminal immediately. You can continue running other commands while the background process runs independently.
Stopping a process:
1. Terminating a foreground process:
- If a process is running in the foreground (i.e., the process is currently receiving input from the terminal), you can stop it by pressing Ctrl+C. This sends an interrupt signal (`SIGINT`) to the process, requesting it to terminate gracefully.
- When you press Ctrl+C, the process will receive the interrupt signal and perform any necessary cleanup actions before terminating. The output may vary depending on the process.
2. Terminating a background process:
- If a process is running in the background, you can stop it using the `kill` command along with the process ID (PID) or the process name.
- To find the process ID (PID) of a specific process, you can use the `ps` command. For example, to list all running processes with their PIDs, you can use: `ps aux` or `ps -ef`.
- Once you have the PID, you can terminate the process using the `kill` command. For example, to stop a process with PID 1234, you can use: `kill 1234`.
- Alternatively, if you know the process name, you can use the `killall` command followed by the process name. This command terminates all processes with the specified name. For example, to stop all Firefox processes, you can use: `killall firefox`.
- When a process receives a termination signal (`SIGTERM`) from the `kill` command, it will exit gracefully, performing any necessary cleanup actions.
Viewing running processes:
1. `ps` command:
- The `ps` command allows you to view information about currently running processes. By default, it shows the processes associated with the current user.
- There are different options available for the `ps` command that control the level of detail displayed. For example:
- `ps aux`: This command shows detailed information about all processes running on the system, including the username, process ID (PID), CPU usage, memory usage, and more.
- ps -ef`: This command displays a full listing of all processes in a hierarchical format, showing the parent-child relationships between processes.
2. `top` command:- The `top` command provides a dynamic view of the currently running processes and system resource usage.
- It updates the displayed information periodically, showing details such as CPU usage, memory usage, process IDs (PIDs), and more.
- When you run the `top` command, you'll see a continuously updating list of processes. Press 'q' to exit the `top` command and return to the terminal.
Viewing running processes:
1. `ps` command:
- The `ps` command allows you to view information about currently running processes. By default, it shows the processes associated with the current user.
- There are different options available for the `ps` command that control the level of detail displayed. For example:
- `ps aux`: This command shows detailed information about all processes running on the system, including the username, process ID (PID), CPU usage, memory usage, and more.
- ps -ef`: This command displays a full listing of all processes in a hierarchical format, showing the parent-child relationships between processes.
2. `top` command:
- The `top` command provides a dynamic view of the currently running processes and system resource usage.
- It updates the displayed information periodically, showing details such as CPU usage, memory usage, process IDs (PIDs), and more.
- When you run the `top` command, you'll see a continuously updating list of processes. Press 'q' to exit the `top` command and return to the terminal.
Comments
Post a Comment