WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [ ? ! ] resource management ; allocating certain cores to a certain process ! ?  (Read 1620 times)

Offline xor

  • Hero Member
  • *****
  • Posts: 1263
[ ? ! ] 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 ?

Offline gadget42

  • Hero Member
  • *****
  • Posts: 663
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline xor

  • Hero Member
  • *****
  • Posts: 1263
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: [Select]
    taskset -cp 4 <PID>
    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: [Select]
# Find PID of Firefox:
pgrep firefox  # Output: 12345

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

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.

« Last Edit: January 13, 2024, 11:43:34 PM by xor »

Offline xor

  • Hero Member
  • *****
  • Posts: 1263
" I know kung fu now! " :) :D
« Reply #3 on: January 14, 2024, 12:24:27 AM »
" I know kung fu now! " :) :D

Code: [Select]

# 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
« Last Edit: January 14, 2024, 12:27:51 AM by xor »

Offline mocore

  • Hero Member
  • *****
  • Posts: 513
  • ~.~
Re: " I know kung fu now! " :) :D
« Reply #4 on: January 18, 2024, 11:21:24 PM »
" I know kung fu now! "
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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11267
Hi mocore
" I know kung fu now! "
presumably an internet chat-bot that goes by the name of `kung fu`(tm) ? ...
No, just a line he stole from the movie The Matrix.