I ran a simple script to generate a large (10000000 lines) csv file with 6 fields in which some fields changed in each line/row, using a while loop. The machine had all (32) CPUs free, lot of RAM (~31 Gb) was free too.
I timed the script with the command
/usr/bin/time -v bash script.01.sh
After running for around 2 hours, I got the following stats:
Command being timed: "bash script.01.sh"
User time (seconds): 1195.14
System time (seconds): 819.71
Percent of CPU this job got: 27%
Elapsed (wall clock) time (h:mm:ss or m:ss): 2:01:10
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 4976
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 3131983488
Voluntary context switches: 22593141
Involuntary context switches: 10923348
Swaps: 0
File system inputs: 0
File system outputs: 2182920
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
I want to know why did my script used only 27% of the CPU? The Disk IO was nothing much at all (saw in vmstat output). So what caused the restriction? The code in the script?
Here is the script:
#!/usr/bin/env bash
number=1
while [[ $number -lt 10000001 ]] ; do
fname="FirstName LastName $"
lname=""
email="fname.lname.$number@domain.com"
password="1234567890"
altemail="lname.fname.$number@domain.com"
mobile="9876543210"
echo "$fname,$lname,$email,$password,$altemail,$mobile" >> /opt/list.csv
number=$(expr $number + 1)
done