Redirect Output in the Middle of a Program??

karish karish at denali.UUCP
Thu Apr 28 11:32:18 AEST 1988


In article <2841 at cvl.umd.edu> liuqing at cvl.UUCP (Larry Liuqing Huang) writes:
>Now more people are dialing into a system via telephone lines. It is
>not unusual that the connection died out in the middle of a big C
>program which you hate to start running from the beginning again.
>
>Is it possible for the C program or Shell to detect the line problem?
>
>If so, is it possible to redirect all standard output and error messages
>to a designated file from the POINT where the problem is detected and 
>continue running?
>
>Any hints highly appreciated.
>
>liuqing at cvl.umd.edu

If the modem on the computer end hangs up when this happens, there is a
way to do what you wish.  The tty driver should send a SIGHUP to the
login process group when the modem hangs up.  The user's program can
catch the SIGHUP, using a signal handler assigned by the signal()
function.  This handler can use fopen() to open outfiles, and
freopen() to reassign the output streams.

It would probably save a lot of programming effort to teach the
users to run their jobs in the background.   This prevents the process
from being killed when the connection dies.

You might also wish to point out the 'nice' and 'tee -f' commands.

Chuck



More information about the Comp.unix.wizards mailing list