Tuesday, December 3, 2013

Run command in Parallel

We can run shell commands in parallel which can be very useful to utilize the power of system
Today system come with multiple CPU and each CPU has multiple cores.
 To utilize the full power of these CPUs you can run shell commands in parallel of different CPU at the same time.

Below is just a small example shows dd command running in parallel using pipe "|" on different CPU :


 # dd if=dev/zero of=/dev/null | dd if=dev/zero of=/dev/null

 #prstat
PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
5080 root     1636K 1040K cpu0    40    0   0:00:24  17% dd/1
5079 root     1636K 1040K cpu3    40    0   0:00:24  17% dd/1

Similarly,
we can gunzip and tar a file :
# gzcat  <file.tar.gz> | tar -xvf -
# gzcat  <file.tar.gz> | tar -xvf -
 

No comments:

Post a Comment