linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* forkpty with streams
@ 2003-07-24 23:28 Andrew Barton
  2003-07-25 13:02 ` Doug McNaught
  2003-07-25 15:27 ` Andries Brouwer
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Barton @ 2003-07-24 23:28 UTC (permalink / raw)
  To: linux-kernel

I've got the 2.4 kernel, and I'm trying to use the forkpty() system call
with the standard I/O stream functions. The calls to forkpty() and
fdopen() and fprintf() all return successfully, but the data never seems
to get to the child process. In this simplified example, I am trying to
open a shell in a pseudo terminal and then send it the string "exit\n"
and then wait for it to die. But the shell apparently never sees the
"exit\n", and the parent waits forever.

#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>

main()
{
	int fd;
	pid_t pid;

	pid = forkpty (&fd, 0, 0, 0);
	if (pid == 0) {
		execlp ("sh", "sh", (void *)0);
		_exit (1);
	} else if (pid == -1) {
		return 1;
	} else {
		FILE *F;

		F = fdopen (fd, "w");
		fprintf (F, "exit\n");
		fflush (F);
		wait (0);
	}
	return 0;
}



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-07-25 19:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-24 23:28 forkpty with streams Andrew Barton
2003-07-25 13:02 ` Doug McNaught
2003-07-25 15:27 ` Andries Brouwer
2003-07-25 10:59   ` Andrew Barton
2003-07-25 18:46     ` Matti Aarnio
2003-07-25 12:53       ` Andrew Barton
2003-07-25 20:10     ` Andries Brouwer

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).