How to exit from the parent script while the child is running?

hi,

i want to call a child shell script from a parent shell script. the child will be running for 5 mins. normally when the child is running, parent will wait till the child completes. so in the above case parent will be paused for 5 mins. is there a way so that the parents does not wait for the child to complete? for example.

parent.sh

echo "parent starts"
. /home/program/child.sh
echo "parent completes"

child.sh

echo "child starts"
sleep 300
echo "child completes"

Put your child process in background using & sign at the end of the child process.

. /home/program/child.sh &
1 Like

There's no point in sourcing the script if you are putting it in the background.

A background process is not executed in the current shell.

1 Like

Just backgrounding a child doesn't insure that it will not respond to HUP... so this is why the nohup command should be used on a child to ensure that it gets parented by the "init" process. If you don't use nohup, depending on what streams are left intact, you might just have a zombie parent and possibly blocked child in the end as well. Nohup is your friend.

1 Like