Fork and exec in bash

How to implement fork and exec in bash?

Assume the script as

echo "Script starts" function_to_fork(){ sleep 5 echo "Hello" } echo "Script ends" 

Basically, I want this function to be called as a new process, such as in C, we use calls to fork and exec ..

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

+59
linux scripting bash shell
Jun 22 '10 at 19:46
source share
2 answers

Use ampersand just like you from the shell.

 #!/usr/bin/bash function_to_fork() { ... } function_to_fork & # ... execution continues in parent process ... 
+102
Jun 22 '10 at 19:49
source share

What about:

 (sleep 5; echo "Hello World") & 
+26
Jun 22 '10 at 19:48
source share



All Articles