pty select test

This commit is contained in:
Ben Gras 2005-08-05 13:47:12 +00:00
parent 5340cf571d
commit 2888e14ed8
2 changed files with 10 additions and 6 deletions

View File

@ -36,3 +36,4 @@ test11: test11.c
test12: test12.c test12: test12.c
test13a: test13a.c test13a: test13a.c
test13b: test13b.c test13b: test13b.c
test14: test14.c

View File

@ -23,6 +23,8 @@
#include <signal.h> #include <signal.h>
#include <libutil.h> #include <libutil.h>
char name[100];
void pipehandler(int sig) void pipehandler(int sig)
{ {
@ -95,7 +97,8 @@ void do_parent(int pty_fds[])
while (1) { while (1) {
FD_ZERO(&fds_write); FD_ZERO(&fds_write);
FD_SET(pty_fds[1], &fds_write); FD_SET(pty_fds[1], &fds_write);
printf("pid %d Waiting for pty ready to write...\n", getpid()); printf("pid %d Waiting for pty ready to write on %s...\n",
getpid(), name);
retval = select(pty_fds[1]+1, NULL, &fds_write, NULL, NULL); retval = select(pty_fds[1]+1, NULL, &fds_write, NULL, NULL);
if (retval == -1) { if (retval == -1) {
perror("select"); perror("select");
@ -131,15 +134,15 @@ void do_parent(int pty_fds[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int pipes[2]; int ptys[2];
int retval; int retval;
int pid; int pid;
if(openpty(&pipes[0], &pipes[1], NULL, NULL, NULL) < 0) { if(openpty(&ptys[0], &ptys[1], name, NULL, NULL) < 0) {
perror("openpty"); perror("openpty");
return 1; return 1;
} }
sleep(50); printf("Using %s\n", name);
pid = fork(); pid = fork();
if (pid == -1) { if (pid == -1) {
fprintf(stderr, "Error forking\n"); fprintf(stderr, "Error forking\n");
@ -147,9 +150,9 @@ int main(int argc, char *argv[])
} }
if (pid == 0) /* child proc */ if (pid == 0) /* child proc */
do_child(pipes); do_child(ptys);
else else
do_parent(pipes); do_parent(ptys);
/* not reached */ /* not reached */
return 0; return 0;