Tiny Core Extensions > TCE Tips & Tricks

[ ? ! ] resource management ; allocating certain cores to a certain process ! ?

(1/2) > >>

[ ? ! ] resource management ; allocating certain cores to a certain process ! ?

example ; It is desired to allocate the 2nd core of the processor only to firefox processes, how is this done ?

had a few seconds to spare and did a quick duckduckgo for "linux processor core allocation"(without the quote marks):

thanks for the answer

I'm considering using this to prevent normally low-consumption applications from being interrupted,
especially when running something that taxes the system.

and also ai's response is as follows


Here's how to allocate specific CPU cores to a process in Linux, using Firefox as an example:

1. Identify the core:

    Use lscpu to list available cores and their numbers. In this case, we want core 2.

2. Find the process ID (PID):

    Use pgrep firefox to get the PID of Firefox processes.

3. Set CPU affinity:

    Use the taskset command:

--- Code: ---    taskset -cp 4 <PID>
--- End code ---

    Kodu kullanırken dikkatli olun. Daha fazla bilgi

        Replace <PID> with the actual PID of the Firefox process.
        -c 4 specifies core 2 (since core numbering starts from 0).


--- Code: ---# Find PID of Firefox:
pgrep firefox  # Output: 12345

# Set affinity to core 2:
taskset -cp 4 12345
--- End code ---

Additional methods and tips:

    CPU affinity mask:
    Use taskset -p <PID> to view the current affinity mask. You can modify it using a hexadecimal value (0x4 for core 2).

    Persistent affinity:
    To make the affinity persist across restarts, use a script or a configuration file for your process manager.

    Isolating multiple cores:
    Separate multiple core numbers with commas: taskset -cp 0,2 12345

    For more complex resource management, explore Cgroups (Control Groups).

Important considerations:

    Thorough testing: Test affinity changes carefully to ensure they improve performance and don't cause stability issues.
    System-wide impact: Be mindful of system-wide resource availability and potential conflicts with other processes.
    Kernel support: Ensure your kernel supports CPU affinity features.

" I know kung fu now! " :) :D

--- Code: ---#!/bin/bash

# Calculate the capacities of the cores
core_capacities=$(ps -eo pid,cpu,affinity | awk '{print $2}')

# Find the core with the lowest capacity
min_core_capacity=$(min $core_capacities)
min_core_number=$(echo $core_capacities | grep -E "^$min_core_capacity$" | awk '{print $1}')

# Find the critical processes
critical_contents="kernel security performance"
critical_processes=$(ps -eo pid,affinity | grep -E "^$min_core_number$" | awk '{print $1}' | while read process; do
    for content in $critical_contents; do
        if [[ $(ps -eo affinity,cmd | grep -E "^$process$" | awk '{print $1}') =~ $content ]]; then
            echo $process

# Move the critical processes to other cores
for process in $critical_processes; do
    taskset -cp $((min_core_number + 1)) $process

# Assign the other workers to other cores
for process in $(ps -eo pid,affinity | grep -E "^$min_core_number$" | grep -vE "$critical_processes"); do
    taskset -cp $((min_core_number + 2)) $process

# Exit the program
exit 0
--- End code ---


--- Quote from: xor on January 14, 2024, 03:24:27 AM ---" I know kung fu now! "

--- End quote ---
presumably an internet chat-bot that goes by the name of `kung fu`(tm) ?

as apposed to building *"form"(kata) to memorize and perfect technique  ???

* https://en.wikipedia.org/wiki/Kata

"The goal is to internalize the movements and techniques of a kata so they can be executed and adapted under different circumstances, without thought or hesitation.
the word has come to be used as a generic term for "forms" in martial arts in general, or even figuratively applied to other fields."

i guess for `other fields` one could add
 "without thought or hesitation..."  web-api calls , or working internet   ;D


[0] Message Index

[#] Next page

Go to full version