Created
November 20, 2024 15:26
-
-
Save vip3r011/c58f29bec2f3d8174579a4cad8b00819 to your computer and use it in GitHub Desktop.
assign process to specific cpu cores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <process_name> <cores_list>" | |
echo "Example: $0 swoole_server 0,1,2" | |
exit 1 | |
fi | |
PROCESS_NAME=$1 | |
CORES_LIST=$2 | |
PID=$(pidof "$PROCESS_NAME" | xargs -n1 | sort | head -n1) | |
if [ -z "$PID" ]; then | |
echo "Error: Process '$PROCESS_NAME' not found." | |
exit 2 | |
fi | |
taskset -cp "$CORES_LIST" "$PID" | |
echo "Process '$PROCESS_NAME' (PID: $PID) has been assigned to cores: $CORES_LIST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment