I believe I can fork 10 child processes from a parent process.
Below is my code:
#/bin/sh
fpfunction(){
n=1
while (($n<20))
do
echo "Hello World-- $n times"
sleep 2
echo "Hello World2-- $n times"
n=$(( n+1 ))
done
}
fork(){
count=0
while (($count<=10))
do
fpfunction &
count=$(( count+1 ))
done
}
fork
However, how can I get the pid from each child process I just created?
Thanks.
From the Bash manual:
i.e., use
$!
.The PID of a backgrounded child process is stored in
$!
.For the reverse, use
$PPID
to get the parent process's PID from the child.Also for what it's worth, you can combine the looping statements into a single C-like for loop: