top` is a command-line utility in Linux that displays real-time information about the system processes, CPU usage, memory usage, and other system statistics. Here are some advanced use cases of `top`:
1. Sorting Processes: `top` allows sorting processes based on different criteria such as CPU usage, memory usage, process ID, and more. To sort by a particular field, press the corresponding key (such as `M` for memory usage) while `top` is running.
2. Changing Refresh Rate: By default, `top` updates the statistics every 3 seconds. However, this can be changed using the `d` command, which allows specifying a new refresh rate in seconds.
3. Displaying Specific Processes: `top` can be used to display information about specific processes by using the `-p` option followed by a comma-separated list of process IDs.
4. Monitoring Processes: `top` can be used to monitor a particular process or a group of processes over time. This is done by using the `-b` option, which runs `top` in batch mode and outputs the system statistics to a file that can be later analyzed.
5. Changing Display Options: `top` allows changing the display options to show or hide different columns of information. This is done by using the `f` command, which displays a list of available fields that can be toggled on or off.
6. Killing Processes: `top` can be used to kill a process directly from the interface. This is done by selecting the process using the arrow keys and pressing `k`, which prompts for the signal to send to the process.
7. System Monitoring: `top` can be used to monitor the overall system performance, including CPU usage, memory usage, and disk I/O. This is done by using the `-b` option to run `top` in batch mode and redirecting the output to a file that can be later analyzed.
[PART 1 - Basic Usage]
Let's start with the basics. To invoke the `top` command, simply open your terminal and type 'top' without any options. You'll be greeted with a dynamic display showing essential information, including:
1. System Uptime: How long your system has been running.
2. Load Average: The average number of processes waiting for CPU time over 1, 5, and 15 minutes.
3. Number of Total Tasks: Total running, sleeping, stopped, and zombie processes.
4. CPU Usage: Usage percentage of each core and the overall CPU.
5. Memory Usage: RAM and swap utilization.
[PART 2 - Sorting Processes]
By default, `top` sorts processes based on CPU usage. However, you can change the sorting order interactively:
- Press 'M' to sort by Memory usage.
- Press 'P' to sort by CPU usage.
- Press 'T' to sort by process execution time.
[PART 3 - Changing Refresh Rate]
The `top` command updates its display at regular intervals. You can control the refresh rate by:
- Pressing 'd' and entering the desired refresh rate in seconds.
[PART 4 - Renicing a Process]
The `renice` command allows you to alter the priority of running processes. To change a process's priority using its Process ID (PID):
1. Find the process ID using `top`.
2. Press 'r' in the `top` interface and enter the PID.
3. Choose the new priority value (higher number for lower priority) and hit Enter.
[PART 5 - Monitoring Threads]
By default, `top` shows only summary information for each process. To display individual threads within processes:
- Press 'H' to toggle thread view.
[PART 6 - Displaying Absolute Paths]
By default, `top` shows only the command name. To display absolute paths of running processes:
- Press 'c' to toggle command display.
[PART 7 - Interactive Process Management]
The `top` command provides interactive process management capabilities. You can send signals to processes directly from the `top` interface:
- Press 'k' to kill a selected process.
- Enter the PID of the process you want to terminate and confirm the action.
[PART 8 - CPU and Memory Information]
The `top` command offers detailed CPU and memory information, including:
- CPU States: The breakdown of CPU usage into user, system, idle, nice, and I/O wait states.
- Memory Utilization: Displaying the total, used, free, and cached memory.
[PART 9 - Load Averages]
The load average values represent the average number of processes in the system's run queue over a specific time frame:
- The first value indicates the average number of processes over the last minute.
- The second value represents the average over the last five minutes.
- The third value shows the average over the last 15 minutes.
[PART 10 - User-Specific Processes]
The `top` command can filter processes by user:
- Press 'u' to filter by a specific user.
- Enter the username to view processes associated with that user only.
[PART 11 - Renicing a Process Group]
Instead of renicing individual processes, you can change the priority of an entire process group:
- Press 'R' and enter the Process Group ID (PGID).
- Choose the new priority value for the process group.
[PART 12 - Saving Configuration]
Customize the `top` display to your preferences and save the configuration for future use:
- Press 'W' to save the current settings to the configuration file `~/.toprc`.
[PART 13 - Searching for Processes]
Easily find specific processes using the `top` search functionality:
- Press 'f' to bring up the Fields Management screen.
- Select the field you want to search (e.g., CPU, memory, command name).
- Enter the search criteria and press Enter.
[PART 14 - Customizing Columns]
Customize the `top` display by choosing the columns you want to see:
- Press 'f' to bring up the Fields Management screen.
- Check or uncheck the desired fields and press Enter to update the display.
Post a Comment