For the simplicity... If i have a shell script as woring below on a FreeBSD 13.1 (nginx, php, mariadb) with 3 vCPUs.
It runs without any problem.
But if I use &, no input at all or sometime only t4 is printed.
If I change to 4 (or more) vCPU, all runs OK.
Why? And how can I store tX strings with (one) & if I have less vCPUs than tX?
I have many tXs and need to store all of them in memory (wait command) to process them later in the script, put them in DB etc. It works with && but not with &, and I need to run all of them in parallel as every tX take long time.
This work’s without any problem. But can’t work with files.
Code:
#!/bin/sh
t1=$(echo "1") &&
t2=$(echo "2") &&
t3=$(echo "3") &&
t4=$(echo "4") &&
wait
echo $t1
echo $t2
echo $t3
echo $t4
It runs without any problem.
But if I use &, no input at all or sometime only t4 is printed.
Code:
#!/bin/sh
t1=$(echo "1") &
t2=$(echo "2") &
t3=$(echo "3") &
t4=$(echo "4") &
wait
echo $t1
echo $t2
echo $t3
echo $t4
If I change to 4 (or more) vCPU, all runs OK.
Why? And how can I store tX strings with (one) & if I have less vCPUs than tX?
I have many tXs and need to store all of them in memory (wait command) to process them later in the script, put them in DB etc. It works with && but not with &, and I need to run all of them in parallel as every tX take long time.
This work’s without any problem. But can’t work with files.
Code:
echo "1" > file1.txt &
echo "2" > file2.txt &
echo "3" > file3.txt &
echo "4" > file4.txt &
wait