Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

detecting background process

0 views
Skip to first unread message

Gino Facini

unread,
Apr 21, 1999, 3:00:00 AM4/21/99
to
I'm fairly new to Unix scripting and I need to know if the script that is
running was started in the background or not. If anyone has an easy way of
telling this could you please email me personally at gino....@gov.nb.ca


Art L.

unread,
Apr 21, 1999, 3:00:00 AM4/21/99
to
I am sure there is a better way, but a method I use is to look at the
return of the tty command.

#!/bin/sh
if [ '`tty`' = "not a tty" ];then
echo "running in background"
else
echo "running in foreground"
fi

On 21 Apr 1999 19:29:28 GMT, "Gino Facini" <gino....@gov.nb.ca>
wrote:

Greg M Lee

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to
I use:
#!/bin/sh
if [ -t 0 ];then
echo "running in foreground"
else
echo "running in background"
fi

Enjoy
-Greg

John DuBois

unread,
Apr 27, 1999, 3:00:00 AM4/27/99
to

Are you using sh or ksh? If sh, the above solutions will work. If ksh (or
another job-control shell), the handling of background jobs is more refined
with the result that the above won't work. This method will work with both:

if {</dev/tty;} 2>/dev/null; then


echo "running in foreground"
else
echo "running in background"
fi


John
--
John DuBois spc...@armory.com. KC6QKZ http://www.armory.com./~spcecdt/

0 new messages