Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Manage Resources in Linux

In any computing environment, managing resources efficiently is crucial for optimal performance and stability. In the Linux environment, resource management is especially important due to the diverse range of applications and services that can run simultaneously. This article will guide you through various aspects of resource management in Linux, including CPU, memory, disk space, and network utilization. We will explore built-in tools and techniques to monitor and control resource usage, ensuring smooth operation of your Linux system.

Examples:

  1. Monitoring CPU Usage: To monitor CPU usage in Linux, you can use the top command. It provides a real-time overview of CPU utilization, processes, and system statistics. Open a terminal and run the following command:

    top

    The output will display a list of processes sorted by their CPU usage. You can press 'q' to exit the top command.

  2. Limiting CPU Usage: If you want to limit the CPU usage of a specific process, you can use the cpulimit command. First, install cpulimit by running the following command:

    sudo apt-get install cpulimit

    Once installed, you can limit the CPU usage of a process by specifying its PID (Process ID) and the desired percentage of CPU usage. For example, to limit a process with PID 1234 to 50% CPU usage, use the following command:

    cpulimit -p 1234 -l 50

  3. Monitoring Memory Usage: To monitor memory usage in Linux, you can use the free command. It provides information about total, used, and available memory. Open a terminal and run the following command:

    free -h

    The output will display memory statistics in human-readable format. The "-h" option is used to display memory sizes in a more understandable format (e.g., GB, MB).

  4. Limiting Memory Usage: Linux provides a built-in mechanism called "cgroups" (control groups) to limit memory usage of processes. With cgroups, you can create resource limits for groups of processes or individual processes. Here's an example of how to limit the memory usage of a process using cgroups:

    1. Create a cgroup directory:

      sudo mkdir /sys/fs/cgroup/memory/mygroup
    2. Set the memory limit for the cgroup:

      echo 100M | sudo tee /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes
    3. Move the process to the cgroup:

      echo <PID> | sudo tee /sys/fs/cgroup/memory/mygroup/cgroup.procs

      Replace <PID> with the actual Process ID.

  5. Monitoring Disk Space: To monitor disk space usage in Linux, you can use the df command. It displays information about the file system disk space usage. Open a terminal and run the following command:

    df -h

    The output will show the disk space usage of all mounted file systems in human-readable format.

  6. Monitoring Network Utilization: To monitor network utilization in Linux, you can use the iftop command. It provides real-time bandwidth usage for network interfaces. Install iftop by running the following command:

    sudo apt-get install iftop

    Once installed, run the following command to start monitoring network utilization:

    sudo iftop

    The output will display a list of network connections and their bandwidth usage.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.