Reputation: 9
I want to run this command multiple times but im not sure how to do it. It has to be a single command. what this command does is it pushes my cpu cores to %100
dd if=/dev/zero of=/dev/null
Its for an assignment. please help if you can thank you
This is what in the assignment says. Maybe it can be helpfull to figure it out
"Figure out how to run multiple instances of the command dd if=/dev/zero of=/dev/null at the same time. You could also use the command sum /dev/zero. You should run one instance per CPU core, so as to push CPU utilization to 100% on all of the CPU cores in your virtual machine. You should be able to launch all of the instances by running a single command or pipeline as a regular user "
so far i tried doing
dd if=/dev/zero of=/dev/null | xargs -p2
but that doesn't do the job right
Upvotes: 0
Views: 5259
Reputation:
Or you could try my home made parallel data transfer tool pdd. This tool spawns several threads and each of the threads is bond to a CPU core.
Upvotes: 0
Reputation: 33748
This will run 4 copies:
dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null
But it is really not recommended as a solution for homework, as it looks as if you do not understand what | does. Here nothing is being sent through the pipe. It has the advantage that it is easy to stop with a Ctrl-C.
If the goal is simply to increase carbon emissions then this is shorter:
burnP6 | burnP6 | burnP6 | burnP6
If you have GNU Parallel:
yes /dev/zero | parallel dd if={} of=/dev/null
yes | parallel burnP6
GNU Parallel starts by default 1 job per CPU core, and thus it only reads that many arguments from yes
.
Upvotes: 1
Reputation: 6768
Your assignment is probably already due and over. But for future readers, here's a single line solution.
perl -e 'print "/dev/zero\n" x'$(nproc --all) | xargs -n 1 -P $(nproc --all) -I{} dd if={} of=/dev/null
How does this work? Let's dissect the pipeline.
nproc --all
will return the number of cores in the system. Let's pretend your system has 4 cores.
perl -e 'print "/dev/zero\n" x 4'
will print 4 lines of /dev/zero
.
Output
/dev/zero
/dev/zero
/dev/zero
/dev/zero
The output of perl is then passed to xargs
.
-n 1
tells xargs
to use only one argument at a time.
-I {}
tells xargs
that the argument shall replace the occurrences of {}
-P 4
tells xargs
to run as many as 4 instances of the command in parallel
A shorter version of the above command can be written like this:
perl -e 'print "if=/dev/zero of=/dev/null\n" x '$(nproc --all) | xargs -n2 -P0 dd
Upvotes: 1
Reputation: 386
Many ways.. for example repeating the command four times:
command & ; command & ; command & ; command &
..or in a more systematic way:
for i in {1..4}
do
dd if=/dev/zero of=/dev/null &
done
Upvotes: 0