From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 22 19:00:38 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 48CB616A423 for ; Tue, 22 Nov 2005 19:00:38 +0000 (GMT) (envelope-from ringworm01@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id C8A3043D9A for ; Tue, 22 Nov 2005 19:00:15 +0000 (GMT) (envelope-from ringworm01@gmail.com) Received: by wproxy.gmail.com with SMTP id i27so653937wra for ; Tue, 22 Nov 2005 11:00:09 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=I1OYX1SCDHlZrlml4ZOgmQDklQWL5v4DPZStJ1s4+93D6e2sCixEkiBCVpuGiv6xwLc3eiAzfx2DMCr80IxTdVcMgYGD7gYKbGJfdf5KIK3lwttz58STLK9k15TpLybeYvhWUbkFSDucGmZnkJ/oCY1BzIKbZ1E1D3XfbCKy9lg= Received: by 10.54.107.10 with SMTP id f10mr3293740wrc; Tue, 22 Nov 2005 11:00:09 -0800 (PST) Received: from ?192.168.1.10? ( [71.102.14.129]) by mx.gmail.com with ESMTP id 45sm1025465wri.2005.11.22.11.00.08; Tue, 22 Nov 2005 11:00:08 -0800 (PST) From: "Michael C. Shultz" To: freebsd-hackers@freebsd.org Date: Tue, 22 Nov 2005 10:50:48 -0800 User-Agent: KMail/1.8.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511221050.49807.ringworm01@gmail.com> Subject: 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 19:00:38 -0000 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