Help! (on ioctl system call)
Randy Smith
paws at sphinx.UChicago.UUCP
Wed Jun 12 03:12:51 AEST 1985
I'm having problems with using the ioctl system call. I eventually
got a sample of the problem I'm having down to the following C program.
-----------------------------------------------------
#include <sys/ioctl.h>
#include <sgtty.h>
#include <stdio.h>
#include <sys/wait.h>
FILE *debug;
main()
{
long me, mepg;
int imepg;
union wait status;
debug = fopen("debug.file","w");
if (!fork()) {
me = getpid();
imepg = (int) mepg = getpgrp((int)me);
fprintf(debug,"Me: %d, Pg: %d\n",me,mepg);
fflush(debug);
fprintf(debug,"Return from setpgrp: %d\n",setpgrp(me,me));
fflush(debug);
fprintf(debug,"Return from ioctl: %d\n",ioctl(1,TIOCSPGRP,&imepg));
fflush(debug);
fprintf(debug,"I made it (thought you'd like to know)\n");
fflush(debug);
exit(0);
}
fprintf(debug,"Pid from wait: %d\n",wait(&status));
fprintf(debug,"Status code returned: %d\n",status);
}
------------------------------------------------------
(forgive the sloppy last printf).
When I copile and run this code, it hangs in the ioctl. My debug
file shows up (after I ^C) looking like:
--------------------------------------------------------
Me: 5567, Pg: 5566
Return from setpgrp: 0
--------------------------------------
If I do a ps (from another terminal) while the thing is hanging, I get:
F UID PID PPID CP PRI NI ADDR SZ RSS WCHAN STAT TTY TIME COMMAND
8201 134 4098 1 0 15 0 ff8b8800 58 14 0 I i05 0:13 -tcsh
408021 134 5217 4098 0 25 0 ff8c4800 202 8 T i05 0:04 emacs
8001 134 5354 4098 0 5 0 ff918000 28 6 b698c I i05 0:00 testio
8001 134 5355 5354 0 4 0 ff954000 36 6 T i05 0:00 testio
8201 134 5373 1 0 15 0 ff8ed800 56 50 0 S i13 0:11 -tcsh
8001 134 5462 5373 34 33 0 ff926800 70 38 R i13 0:00 ps glx
8001 134 5463 5373 4 1 0 ff93c800 30 10 3f944 S i13 0:00 tee ex
where testio is the name of the program, and tee and emacs should be ignored.
Why is this call hanging on me? I'm on a Pyramid 90x, but I got the same
(ie. confusing enough that I couldn't tell the difference) results on a
VAX 750. Suggestions from the net?
-- Randy Smith
P.S. If the parent process doesn't wait for the child, the child EXITS
during the ioctl.
UUcp: . . . ihnp4!gargoyle!sphinx!paws
Arpa: dvlp.dilvish%uchicago.mailnet at mit-multics.arpa
CSnet: randy at uchicago.csnet
More information about the Comp.unix.wizards
mailing list