It seems some answers on the site but those seem not to resolve my question.
Say,
#/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
I am expecting to "fork" this parent process to the number of 10 child processes.
The way I check that those child processes are actually created is to type "ps -l" command.
I am a newbie to the shell world and please let me know how to archive this.
Thanks in advance.
Child Process: A child process is created by a parent process in an operating system using a fork() system call. A child process may also be known as subprocess or a subtask. A child process is created as a copy of its parent process. The child process inherits most of its attributes.
fork() in C. Fork system call is used for creating a new process, which is called child process, which runs concurrently with the process that makes the fork() call (parent process). After a new child process is created, both processes will execute the next instruction following the fork() system call.
Upon successful completion, fork() returns 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, -1 is returned to the parent process, no child process is created, and errno is set to indicate the error.
fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.
The ampersand (&
) after a command will run it in a forked subshell.
fpfunction &
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With