Operating System - Linux
1828038 Members
1925 Online
109973 Solutions
New Discussion

scripting a background process

 
SOLVED
Go to solution
Timothy P. Jackson
Valued Contributor

scripting a background process

Hello everyone,

I am writing a script that works perfectly in the fore ground. The script starts a background process that monitors the parent process so that it knows when it is done. The background process writes time updates to the screen so that the user knows that the parent process is still running. The problem I am having is that if I try to run the parent script in the background I get a SIGTTOU message and the script stops until I bring it back into the fore ground.

I know the problem is with the script trying to write to the crontroling tty and it can't but I am not sure if there is a way around it. Does any one have any ideas?

I hope this all made sense!!

Thanks,
Tim
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: scripting a background process

Add a trap to the writing process telling it to ignore SIGTTOU.

bear in mind that there is another better way to determine if a background process is still running.

child_proc.sh &
CHILD_PID=${!}

Now periodically do
kill -0 ${CHILD_PID}
CHILD_STAT=${?}
if [[ ${CHILD_STAT} -eq 0 ]]
then
echo "The kid is still running"
fi
If it ain't broke, I can fix that.
Timothy P. Jackson
Valued Contributor

Re: scripting a background process

Thanks Clay!

This makes total sense and probably more efficient.

Tim