Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Nov 2005 10:50:48 -0800
From:      "Michael C. Shultz" <ringworm01@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Question about closeing and opening stdin
Message-ID:  <200511221050.49807.ringworm01@gmail.com>

next in thread | raw e-mail | index | archive | help

How do I close then open stdin and keep it set to the same terminal
as when it was closed?  Everything I've tried so far has met with failure
accept this works sort of and I don't get why:

signal( SIGALRM, MGPMrTimer );
alarm( 300 );	/* time out in 5 minutes */
answer	= getc(stdin);

the signal handler just closes descriptor 0 if a timeout occrs:

close( 0 )


then to reset stdin I tried this:

stdinFileDescriptor = open( "/dev/tty", O_RDWR ) )
stdin = fdopen( stdinFileDescriptor, "r" );

and it works in this instance of the program, but
if a second instance is started the second instance can't
close stdin.

I got the above idea from google, what I don't understand though
is there is no /dev/tty!  So anyone have any suggested books
I might read or tips so I can learn how to do this right, and understand
why it works?

Thank you,

Mike



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511221050.49807.ringworm01>