Skip to content

Instantly share code, notes, and snippets.

@vip3r011
Created November 20, 2024 15:26
Show Gist options
  • Save vip3r011/c58f29bec2f3d8174579a4cad8b00819 to your computer and use it in GitHub Desktop.
Save vip3r011/c58f29bec2f3d8174579a4cad8b00819 to your computer and use it in GitHub Desktop.
assign process to specific cpu cores
#!/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