From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 22 22:40:05 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7939716A41F for ; Tue, 22 Nov 2005 22:40:05 +0000 (GMT) (envelope-from ringworm01@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id A1A9943D5E for ; Tue, 22 Nov 2005 22:40:04 +0000 (GMT) (envelope-from ringworm01@gmail.com) Received: by xproxy.gmail.com with SMTP id s9so970182wxc for ; Tue, 22 Nov 2005 14:40:04 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=NO8bWiArWxmyzq5sB4mfb0BegxOqB9xdQPjgfvhKMBISRQy2TtVT7hRxgqDEcJxqwzHYbQSQSD8Ivs9vyLn6STpIPDZwEQTyf8QAEUhsne9vNti6JvVbN6qG3vvZqhjK1dL1EFZw2FuhD7g4JkhGWvbL9HW//jryrkIXtY30vn0= Received: by 10.70.103.10 with SMTP id a10mr4145109wxc; Tue, 22 Nov 2005 13:34:07 -0800 (PST) Received: from ?192.168.1.10? ( [71.102.14.129]) by mx.gmail.com with ESMTP id h35sm2354951wxd.2005.11.22.13.34.06; Tue, 22 Nov 2005 13:34:07 -0800 (PST) From: "Michael C. Shultz" To: freebsd-hackers@freebsd.org Date: Tue, 22 Nov 2005 13:24:49 -0800 User-Agent: KMail/1.8.3 References: <200511221050.49807.ringworm01@gmail.com> In-Reply-To: <200511221050.49807.ringworm01@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511221324.49439.ringworm01@gmail.com> Subject: Re: Question about closeing and opening stdin X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2005 22:40:05 -0000 On Tuesday 22 November 2005 10:50, Michael C. Shultz wrote: > 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 Please disregard the previous post, I figured it out, simple solution. -Mike