Abhijeet Rastogi Abhijeet Rastogi - 1 year ago 143
Linux Question

fork and exec in bash

How do I implement fork and exec in bash?

Let us suppose script as

echo "Script starts"

sleep 5
echo "Hello"

echo "Script ends"

Basically I want that function to be called as new process like in C we use fork and exec calls..

From the script it is expected that the parent script will end and then after 5 seconds, "Hello" is printed.

mob mob
Answer Source

Use the ampersand just like you would from the shell.

function_to_fork() {

function_to_fork &
# ... execution continues in parent process ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download