casapt.blogg.se

Bash script to monitor cpu and memory usage
Bash script to monitor cpu and memory usage








bash script to monitor cpu and memory usage bash script to monitor cpu and memory usage bash script to monitor cpu and memory usage

However, they can only display the numbers in the command prompt. Linux offers us some handy commands to obtain a view of system resource usage of specific tasks. Without this parameter, it will only display the digits instead. The –human parameter will display the percentage numbers in a ‘*.*%” style. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND Here is how we shall use the pidstat command: $ ps aux If we don’t know the process id we are looking for, we need first to use the ps command to find that number. We should install this package first using this command: $ sudo snap install sysstatĪfter installing this package, we can use the included pidstat command to do our bidding. This command is part of the sysstat package, which is not vanilla Linux, but we can still find the documentation of this command on the man page. On the other hand, this makes this command a lightweight process. However, it only gives us a snapshot of current resource usage when we run this command, rather than providing a real-time view as we can expect from the top command. Linux offers another command named pidstat to check the percentage of resources being used. We probably need to use some third-party add-ons to provide a better idea. However, the display is not very user-friendly. The shell will refresh this screen once every a couple of seconds to give us an updated view of a process’ status. Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie Once we find the process id, we can feed the number into the top command in this manner: $ top -p 2225 We can find the process id of a named process using the ps command. When using the -p parameter, we often want to include the process id. If we want to have an idea of a single process, we can use the -p parameter. This command displays a real-time view of a running system in the command prompt. Usually, we can use the Linux built-in top command.










Bash script to monitor cpu and memory usage