linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Winters <cwinters@atl.lmco.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: opening standard streams - who does that?
Date: Mon, 8 Jul 2002 13:53:29 -0400	[thread overview]
Message-ID: <20020708135329.A3340@atl.lmco.com> (raw)
In-Reply-To: <15655.60733.125157.459144@cerise.nosuchdomain.co.uk>; from glynn.clements@virgin.net on Sun, Jul 07, 2002 at 08:26:53AM +0100

On the same note, I have a program which uses another library.  Is it possible to
redirect stderr to a file, and then later set it back to stderr.  I know I can close
stderr, then reopen stderr to the file I want.  The problem is that when I run the 
following code, I get a, "No Such File or Directory" error.

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
	FILE *f = NULL;

	fclose(stdout);

	if( !(f = fopen("/dev/stdout", "w+")) ) {
		perror("Opening stdout");
		exit(1);
	}

	fprintf(stdout, "Hey\n");
	exit(0);
}

Chuck Winters

On Sun, Jul 07, 2002 at 08:26:53AM +0100, Glynn Clements wrote:
> 
> Suriya Narayanan M S wrote:
> 
> > 	I want to know who opens the streams
> > stdin, stdout, stderr in file-descriptors 1, 2, 3
> 
> 0, 1, 2
> 
> > and calls the process. I know (right or wrong?)
> > that on a fork the filedescriptors are duplicated.
> 
> Yes.
> 
> > So bash or the shell can just forks a new process
> > without assinging the fds. Is it the kernel
> > which assigns 0 to the keyboard. How is this
> > done?
> 
> For terminal logins, it's done by getty[1], which is run from the
> inittab.
> 
> [1] "getty" is the generic term; the program may actually be called
> something else, e.g. agetty, mgetty, uugetty, mingetty.
> 
> For telnet/ssh/rsh etc logins, it's done by the daemon (in.telnetd,
> sshd, in.rshd etc).
> 
> Under X, terminal emulators (xterm etc) set up the descriptors. Note
> that programs which aren't run from a terminal, but from the X session
> scripts (~/.xsession, ~/.xinitrc) or from the window manager, may not
> actually have stdin/stdout/stderr assigned.
> 
> -- 
> Glynn Clements <glynn.clements@virgin.net>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2002-07-08 17:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-06 15:30 opening standard streams - who does that? Suriya Narayanan M S
2002-07-07  7:26 ` Glynn Clements
2002-07-08 17:53   ` Chuck Winters [this message]
2002-07-08 20:27     ` Marius Nita

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020708135329.A3340@atl.lmco.com \
    --to=cwinters@atl.lmco.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).