Created
July 24, 2012 19:11
-
-
Save nhoffman/3171967 to your computer and use it in GitHub Desktop.
Demonstrate parallel processes using xargs
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 | |
# try me out: | |
# two processors | |
# $ echo {1..9} | xargs -n1 -P2 ./ps.sh | |
# four processors | |
# $ echo {1..9} | xargs -n1 -P4 ./ps.sh | |
# sleeptime set to a random integer between 2 and 5 | |
sleeptime=$(shuf -i 2-5 -n 1) | |
# '$$' is the current process id | |
# 'ps -o pid,psr' gives the process id and cpu id of current processes | |
# '$(ps -o pid,psr | grep $$)' gives the process id and cpu id of the current process | |
echo i,process,cpu,sleeptime: $1 $(ps -o pid,psr | grep $$) $sleeptime | |
sleep $sleeptime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment