Re: Question about closeing and opening stdin

From: Michael C. Shultz (ringworm01_at_gmail.com)
Date: 11/22/05

  • Next message: Vladimir Kushnir: "Re: ATI drivers for FreeBSD - anything?"
    To: freebsd-hackers@freebsd.org
    Date: Tue, 22 Nov 2005 13:24:49 -0800
    
    

    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

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Vladimir Kushnir: "Re: ATI drivers for FreeBSD - anything?"

    Relevant Pages

    • Re: Question about closeing and opening stdin
      ... >> How do I close then open stdin and keep it set to the same terminal ... >> if a second instance is started the second instance can't ... >> close stdin. ... fclose(local_stdin); ...
      (freebsd-hackers)
    • Question about closeing and opening stdin
      ... How do I close then open stdin and keep it set to the same terminal ... the signal handler just closes descriptor 0 if a timeout occrs: ... if a second instance is started the second instance can't ...
      (freebsd-hackers)
    • Re: signal(SIGCHLD, Handler) Problem
      ... So your question is really "why does fgets(..., stdin) ... because you didn't set your signal handler ... switch (pid) { ... fprintf(stderr, "main returns, errno %d (%s)\n", errno, ...
      (comp.os.linux.development.system)
    • Re: signal(SIGCHLD, Handler) Problem
      ... So your question is really "why does fgets(..., stdin) ... because you didn't set your signal handler ... switch (pid) { ... fprintf(stderr, "main returns, errno %d (%s)\n", errno, strerror); ...
      (comp.os.linux.development.system)
    • Re: How to to kill a c program at the exit of my gui?
      ... > is EOF of stdin, ... So I want the recv program to know this ... and use the corresponding signal handler to kill itself. ...
      (comp.lang.tcl)