Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Last active December 9, 2023 14:04
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chockenberry/e33df6b0f4f201bd161763946158c11c to your computer and use it in GitHub Desktop.
Save chockenberry/e33df6b0f4f201bd161763946158c11c to your computer and use it in GitHub Desktop.
A simple shell script to reset CoreSimulator
#!/bin/sh
pids=`ps axo pid,command | grep CoreSimulator | grep -v "grep CoreSimulator" | cut -c 1-5`
if [ "$1" = "go" ]; then
kill -9 $pids
elif [ "$1" = "echo" ]; then
echo $pids
else
pid_param=`echo $pids | tr -s ' ' ','`
ps -p $pid_param -o pid,command
fi
@hisaac
Copy link

hisaac commented Aug 21, 2023

If I'm reading right, the cut -f 1 -d " " at the end of the first command omits results that start with a space, meaning the pids that are only 4 digits long. How come? I'm just not familiar enough with this to know why.

@chockenberry
Copy link
Author

@hisaac Good catch. I've updated the script so it just uses column position 1 through 5. That catches the process ids with less than 5 digits.

@rdj
Copy link

rdj commented Oct 2, 2023

In case they're not in your arsenal, check out pgrep/pkill.

@MarcusP-P
Copy link

Rather than the grep/grep -v you can use grep "[C]oreSimulator". The regexp won't match the parameter to grep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment