Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!agate!eos!labrea!denali!karish From: karish@denali.UUCP (karish) Newsgroups: comp.unix.wizards Subject: Re: Redirect Output in the Middle of a Program?? Message-ID: <62@denali.UUCP> Date: 28 Apr 88 01:32:18 GMT References: <13085@brl-adm.ARPA> <3571@gryphon.CTS.COM> <2841@cvl.umd.edu> Reply-To: karish@denali.stanford.edu (Chuck Karish) Organization: Mindcraft, Inc. Lines: 28 In article <2841@cvl.umd.edu> liuqing@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@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