WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline xor

  • Hero Member
  • *****
  • Posts: 1268
[ ? ! ] 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: 762
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: 1268
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:
    Bash
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).

Example:
Bash
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

    Cgroups:
    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 14, 2024, 02:43:34 AM by xor »

Offline xor

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

Code: [Select]
#!/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
            break
        fi
    done
done)

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

# 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
done

# Exit the program
exit 0
« Last Edit: January 14, 2024, 03:27:51 AM by xor »

Offline mocore

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