<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://serverrental.store/index.php?action=history&amp;feed=atom&amp;title=Process_Management_in_Linux</id>
	<title>Process Management in Linux - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://serverrental.store/index.php?action=history&amp;feed=atom&amp;title=Process_Management_in_Linux"/>
	<link rel="alternate" type="text/html" href="https://serverrental.store/index.php?title=Process_Management_in_Linux&amp;action=history"/>
	<updated>2026-04-15T01:05:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://serverrental.store/index.php?title=Process_Management_in_Linux&amp;diff=5827&amp;oldid=prev</id>
		<title>Admin: New server guide</title>
		<link rel="alternate" type="text/html" href="https://serverrental.store/index.php?title=Process_Management_in_Linux&amp;diff=5827&amp;oldid=prev"/>
		<updated>2026-04-13T20:02:44Z</updated>

		<summary type="html">&lt;p&gt;New server guide&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article will guide you through essential process management techniques in Linux, covering `systemd`, `supervisord`, process priorities, and `cgroups`. Effective process management is crucial for maintaining server stability, performance, and security.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* Basic understanding of the Linux command line.&lt;br /&gt;
* Root or sudo privileges on your Linux server.&lt;br /&gt;
* A running Linux server (e.g., Ubuntu, CentOS, Debian).&lt;br /&gt;
* Familiarity with text editors like `nano` or `vim`.&lt;br /&gt;
&lt;br /&gt;
== Understanding Processes in Linux ==&lt;br /&gt;
A process is an instance of a running program. Each process has a unique Process ID (PID), which is used by the operating system to manage and track it. Understanding how processes are managed is fundamental to server administration.&lt;br /&gt;
&lt;br /&gt;
=== Key Concepts ===&lt;br /&gt;
*   **PID (Process ID):** A unique number assigned to each running process.&lt;br /&gt;
*   **Parent Process:** A process that creates another process (child process).&lt;br /&gt;
*   **Child Process:** A process created by another process.&lt;br /&gt;
*   **Daemon:** A background process that runs without direct user interaction, often providing services.&lt;br /&gt;
&lt;br /&gt;
== Managing Processes with systemd ==&lt;br /&gt;
`systemd` is the modern init system and service manager for most Linux distributions. It's responsible for starting, stopping, and managing services (daemons) at boot time and throughout the system's lifecycle.&lt;br /&gt;
&lt;br /&gt;
=== Creating a systemd Service File ===&lt;br /&gt;
To manage a custom application as a service, you'll create a `.service` unit file.&lt;br /&gt;
&lt;br /&gt;
1.  **Create the service file:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/systemd/system/my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
2.  **Add the following content:**&lt;br /&gt;
    ```ini&lt;br /&gt;
    [Unit]&lt;br /&gt;
    Description=My Custom Application Service&lt;br /&gt;
    After=network.target&lt;br /&gt;
&lt;br /&gt;
    [Service]&lt;br /&gt;
    ExecStart=/usr/local/bin/my_app --config /etc/my_app/config.conf&lt;br /&gt;
    Restart=on-failure&lt;br /&gt;
    User=my_app_user&lt;br /&gt;
    Group=my_app_group&lt;br /&gt;
    WorkingDirectory=/opt/my_app&lt;br /&gt;
&lt;br /&gt;
    [Install]&lt;br /&gt;
    WantedBy=multi-user.target&lt;br /&gt;
    ```&lt;br /&gt;
    *   **`[Unit]` Section:**&lt;br /&gt;
        *   `Description`: A human-readable description of the service.&lt;br /&gt;
        *   `After`: Specifies that this service should start after the `network.target` is reached, ensuring network connectivity is available.&lt;br /&gt;
    *   **`[Service]` Section:**&lt;br /&gt;
        *   `ExecStart`: The command to execute to start the application. Ensure the path to your application is correct.&lt;br /&gt;
        *   `Restart=on-failure`: Configures `systemd` to automatically restart the service if it exits with a non-zero status code (indicating an error).&lt;br /&gt;
        *   `User`/`Group`: Specifies the user and group under which the service will run. This is a critical security practice to limit the service's privileges.&lt;br /&gt;
        *   `WorkingDirectory`: The directory where the application will be executed.&lt;br /&gt;
    *   **`[Install]` Section:**&lt;br /&gt;
        *   `WantedBy=multi-user.target`: Defines the target that this service should be enabled for. `multi-user.target` is the standard runlevel for a non-graphical, multi-user system.&lt;br /&gt;
&lt;br /&gt;
3.  **Reload systemd to recognize the new service:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl daemon-reload&lt;br /&gt;
    ```&lt;br /&gt;
    **Why this step is important:** `daemon-reload` tells `systemd` to rescan its unit files and load any new or modified configurations.&lt;br /&gt;
&lt;br /&gt;
4.  **Enable the service to start on boot:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl enable my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
    **Why this step is important:** This creates a symbolic link from the `multi-user.target.wants` directory to your service file, ensuring it's started automatically when the system boots into that target.&lt;br /&gt;
&lt;br /&gt;
5.  **Start the service:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl start my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
6.  **Check the service status:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl status my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
    **Expected Output Snippet:**&lt;br /&gt;
    ```&lt;br /&gt;
    ● my_app.service - My Custom Application Service&lt;br /&gt;
         Loaded: loaded (/etc/systemd/system/my_app.service; enabled; vendor preset: enabled)&lt;br /&gt;
         Active: active (running) since Tue 2023-10-27 10:00:00 UTC; 1min ago&lt;br /&gt;
       Main PID: 12345 (my_app)&lt;br /&gt;
          Tasks: 1 (limit: 4915)&lt;br /&gt;
         Memory: 5.0M&lt;br /&gt;
            CPU: 100ms&lt;br /&gt;
         CGroup: /system.slice/my_app.service&lt;br /&gt;
                 └─12345 /usr/local/bin/my_app --config /etc/my_app/config.conf&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
7.  **Stop the service:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl stop my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
8.  **Restart the service:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl restart my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting systemd Services ===&lt;br /&gt;
*   **Service not starting:** Check `sudo systemctl status my_app.service` for error messages. Examine application logs, which can often be found in `/var/log/` or specified within the application's configuration.&lt;br /&gt;
*   **Permission denied:** Ensure the `User` and `Group` specified in the service file have the necessary permissions to access the application executable, configuration files, and any directories it needs to write to.&lt;br /&gt;
*   **Application crashes immediately:** Verify the `ExecStart` command is correct and that the application runs successfully when executed manually from the command line as the specified user.&lt;br /&gt;
&lt;br /&gt;
== Managing Processes with supervisord ==&lt;br /&gt;
`supervisord` is a process control system that allows you to monitor and control a number of processes on UNIX-like operating systems. It's particularly useful for managing applications that are not designed to run as system daemons or when you need more fine-grained control over child processes.&lt;br /&gt;
&lt;br /&gt;
=== Installing and Configuring supervisord ===&lt;br /&gt;
1.  **Install supervisord:**&lt;br /&gt;
    *   **Debian/Ubuntu:**&lt;br /&gt;
        ```bash&lt;br /&gt;
        sudo apt update&lt;br /&gt;
        sudo apt install supervisor&lt;br /&gt;
        ```&lt;br /&gt;
    *   **CentOS/RHEL:**&lt;br /&gt;
        ```bash&lt;br /&gt;
        sudo yum install epel-release&lt;br /&gt;
        sudo yum install supervisor&lt;br /&gt;
        ```&lt;br /&gt;
&lt;br /&gt;
2.  **Create a configuration file for your application:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/supervisor/conf.d/my_app.conf&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
3.  **Add the following content:**&lt;br /&gt;
    ```ini&lt;br /&gt;
    [program:my_app]&lt;br /&gt;
    command=/usr/local/bin/my_app --config /etc/my_app/config.conf&lt;br /&gt;
    directory=/opt/my_app&lt;br /&gt;
    user=my_app_user&lt;br /&gt;
    autostart=true&lt;br /&gt;
    autorestart=true&lt;br /&gt;
    stderr_logfile=/var/log/supervisor/my_app.err.log&lt;br /&gt;
    stdout_logfile=/var/log/supervisor/my_app.out.log&lt;br /&gt;
    ```&lt;br /&gt;
    *   **`[program:my_app]`:** Defines a program named `my_app`.&lt;br /&gt;
    *   `command`: The command to run the application.&lt;br /&gt;
    *   `directory`: The working directory for the command.&lt;br /&gt;
    *   `user`: The user to run the command as.&lt;br /&gt;
    *   `autostart=true`: Automatically start this program when `supervisord` starts.&lt;br /&gt;
    *   `autorestart=true`: Automatically restart the program if it exits.&lt;br /&gt;
    *   `stderr_logfile`/`stdout_logfile`: Paths for standard error and standard output logs.&lt;br /&gt;
&lt;br /&gt;
4.  **Create the log directory if it doesn't exist:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo mkdir -p /var/log/supervisor&lt;br /&gt;
    sudo chown my_app_user:my_app_group /var/log/supervisor # Adjust ownership if needed&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
5.  **Update supervisord's configuration:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo supervisorctl reread&lt;br /&gt;
    sudo supervisorctl update&lt;br /&gt;
    ```&lt;br /&gt;
    **Why these steps are important:** `reread` tells `supervisord` to re-examine its configuration files, and `update` applies the changes, starting or stopping programs as defined in the new configuration.&lt;br /&gt;
&lt;br /&gt;
6.  **Check the status of your application:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo supervisorctl status my_app&lt;br /&gt;
    ```&lt;br /&gt;
    **Expected Output Snippet:**&lt;br /&gt;
    ```&lt;br /&gt;
    my_app                         RUNNING   PID 12346, uptime 0:01:30&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
7.  **To stop, start, or restart:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo supervisorctl stop my_app&lt;br /&gt;
    sudo supervisorctl start my_app&lt;br /&gt;
    sudo supervisorctl restart my_app&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting supervisord ===&lt;br /&gt;
*   **Program not starting:** Use `sudo supervisorctl status` to see if it's running. Check `sudo supervisorctl tail my_app stderr` and `sudo supervisorctl tail my_app stdout` for error messages from the application.&lt;br /&gt;
*   **Permission errors:** Ensure the `user` specified in the `.conf` file has read/write permissions to log files and any directories the application needs.&lt;br /&gt;
*   **Configuration changes not applied:** Always run `sudo supervisorctl reread` and `sudo supervisorctl update` after modifying `.conf` files.&lt;br /&gt;
&lt;br /&gt;
== Process Priorities (Nice Values) ==&lt;br /&gt;
Process priority determines how much CPU time a process receives. Linux uses &amp;quot;nice&amp;quot; values to control this. A lower nice value means a higher priority (more CPU time), and a higher nice value means a lower priority (less CPU time). The range is typically -20 (highest priority) to +19 (lowest priority).&lt;br /&gt;
&lt;br /&gt;
=== Adjusting Process Priority ===&lt;br /&gt;
*   **To run a command with a lower priority (higher nice value):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    nice -n 10 your_command&lt;br /&gt;
    ```&lt;br /&gt;
    This will run `your_command` with a nice value of 10.&lt;br /&gt;
&lt;br /&gt;
*   **To run a command with a higher priority (lower nice value):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo renice -n -5 -p &amp;lt;PID&amp;gt;&lt;br /&gt;
    ```&lt;br /&gt;
    This command increases the priority of an already running process with PID `&amp;lt;PID&amp;gt;` (requires root privileges for negative nice values).&lt;br /&gt;
&lt;br /&gt;
*   **To check the nice value of a running process:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    ps -eo pid,ni,comm&lt;br /&gt;
    ```&lt;br /&gt;
    The `NI` column shows the nice value.&lt;br /&gt;
&lt;br /&gt;
**Why this matters:** You can use nice values to ensure critical processes get enough CPU resources while less important background tasks don't monopolize the CPU, improving overall system responsiveness.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting Priority Issues ===&lt;br /&gt;
*   **Cannot set negative nice value:** You need root privileges (`sudo`) to increase a process's priority (decrease its nice value).&lt;br /&gt;
*   **Process still slow:** While priority affects CPU allocation, it doesn't solve other performance bottlenecks like I/O wait or insufficient RAM. Use tools like `top`, `htop`, and `iostat` to diagnose other issues.&lt;br /&gt;
&lt;br /&gt;
== Control Groups (cgroups) ==&lt;br /&gt;
Control Groups (cgroups) are a Linux kernel feature that allows you to allocate, limit, and prioritize system resources (CPU, memory, I/O, network) for a collection of processes. `systemd` heavily utilizes cgroups for resource management.&lt;br /&gt;
&lt;br /&gt;
=== Understanding cgroups ===&lt;br /&gt;
*   **Hierarchical Structure:** Cgroups are organized in a hierarchy, allowing for complex resource allocation policies.&lt;br /&gt;
*   **Controllers:** Different controllers manage specific resources (e.g., `cpu`, `memory`, `blkio`).&lt;br /&gt;
*   **Systemd Integration:** `systemd` automatically places services it manages into their own cgroups, making it easier to manage resource limits for individual services.&lt;br /&gt;
&lt;br /&gt;
=== Basic cgroup Management (via systemd) ===&lt;br /&gt;
While direct manipulation of cgroups can be complex, `systemd` provides a user-friendly way to set resource limits for services.&lt;br /&gt;
&lt;br /&gt;
1.  **Edit the systemd service file** (e.g., `/etc/systemd/system/my_app.service`).&lt;br /&gt;
&lt;br /&gt;
2.  **Add resource control directives to the `[Service]` section:**&lt;br /&gt;
    ```ini&lt;br /&gt;
    [Unit]&lt;br /&gt;
    Description=My Custom Application Service&lt;br /&gt;
    After=network.target&lt;br /&gt;
&lt;br /&gt;
    [Service]&lt;br /&gt;
    ExecStart=/usr/local/bin/my_app --config /etc/my_app/config.conf&lt;br /&gt;
    Restart=on-failure&lt;br /&gt;
    User=my_app_user&lt;br /&gt;
    Group=my_app_group&lt;br /&gt;
    WorkingDirectory=/opt/my_app&lt;br /&gt;
&lt;br /&gt;
    # CPU and Memory Limits&lt;br /&gt;
    CPUQuota=50%           # Limit CPU usage to 50% of one core&lt;br /&gt;
    MemoryMax=256M         # Limit memory usage to 256MB&lt;br /&gt;
    MemorySwapMax=0        # Disable swap usage for this service&lt;br /&gt;
&lt;br /&gt;
    [Install]&lt;br /&gt;
    WantedBy=multi-user.target&lt;br /&gt;
    ```&lt;br /&gt;
    *   `CPUQuota`: Limits the CPU time the service can use. `50%` means it can use at most half of one CPU core. You can also use `CPUShares` for relative weighting.&lt;br /&gt;
    *   `MemoryMax`: Sets a hard limit on memory usage.&lt;br /&gt;
    *   `MemorySwapMax`: Controls swap usage. `0` disables it.&lt;br /&gt;
&lt;br /&gt;
3.  **Reload systemd and restart the service:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl daemon-reload&lt;br /&gt;
    sudo systemctl restart my_app.service&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
4.  **Monitor resource usage:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    systemd-cgtop&lt;br /&gt;
    ```&lt;br /&gt;
    This command provides a real-time view of resource usage by cgroups, similar to `top` but for cgroups.&lt;br /&gt;
&lt;br /&gt;
**Why this matters:** Cgroups are essential for preventing runaway processes from consuming all system resources, ensuring stability and fair resource distribution, especially in multi-tenant environments or when running multiple demanding applications.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting cgroups ===&lt;br /&gt;
*   **Service failing to start with resource limits:** Ensure the limits are reasonable for your application. A limit set too low might prevent the application from even starting. Check `journalctl -u my_app.service` for specific error messages.&lt;br /&gt;
*   **Application behaving erratically:** If an application is hitting its memory limit, it might be killed by the OOM (Out-Of-Memory) killer. Check system logs (`/var/log/syslog` or `journalctl`) for OOM killer messages.&lt;br /&gt;
*   **`systemd-cgtop` shows unexpected usage:** Verify that the correct service is associated with the cgroup you are monitoring. Ensure no other processes are inadvertently grouped with your service.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
Mastering process management with tools like `systemd` and `supervisord`, understanding process priorities, and leveraging `cgroups` for resource control are fundamental skills for any Linux system administrator. These techniques empower you to build robust, performant, and secure server environments.&lt;br /&gt;
&lt;br /&gt;
[[Category:Optimization]]&lt;br /&gt;
[[Category:System Administration]]&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>