2010e$BG/e(B8e$B7ne(B11e$BF|e(B8:05 NARUSE, Yui [email protected]:
e$B$"$H!"e(Bps e$B$Ge(B wchan e$B$r8+$F$_$k$H!"0J2<$N$h$&$K$J$j$^$9$Me(B
% pgrep a.out|xargs procstat
PID PPID PGID SID TSID THR LOGIN WCHAN EMUL COMM
35305 35304 35304 47112 47112 1 naruse ttyout FreeBSD ELF64 a.out
35304 47112 35304 47112 47112 1 naruse wait FreeBSD ELF64 a.out
e$B$3$l$ONI$$>pJs$G$9!#e(B
ttyout e$B$C$F$3$H$O$J$K$+=PNO$rBT$C$F$$$k$s$G$9$M!#e(B
e$B;R%W%m%;%9$b<h$j=|$1$^$7$?!#e(B
freebsd8% cat tst.c
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int m, s;
char *slavedev;
if ((m = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
perror(“posix_openpt”); exit(1); }
if (grantpt(m) == -1) { perror(“grantpt”); exit(1); }
if (unlockpt(m) == -1) { perror(“unlockpt”); exit(1); }
if ((slavedev = ptsname(m)) == NULL) { perror(“ptsname”); exit(1); }
if ((s = open(slavedev, O_RDWR|O_NOCTTY, 0)) == -1) {
perror(“open”); exit(1); }
if (write(m, “a”, 1) == -1) { perror(“write”); exit(1); }
fprintf(stderr, “before close(s)\n”);
if (close(s) == -1) { perror(“close”); exit(1); }
fprintf(stderr, “after close(s)\n”);
return 0;
}
freebsd8% gcc -Wall tst.c
freebsd8% ./a.out
before close(s)
(e$B$3$3$G%O%s%0e(B)
e$B$I$&$d$i!"e(Bclose e$B$,%V%m%C%/$7$F$$$k$h$&$G$9$M!#e(B
exit e$B$bFbItE*$K$Oe(B close e$BAjEv$N$3$H$r$9$k$G$7$g$&$+$i!"e(B
e$B$=$3$G%V%m%C%/$7$F$$$k$N$G$7$g$&!#e(B
e$B0J2<$N$h$&$K$7$F$b%O%s%0$7$^$9!#e(B
% ./ruby -rpty -e ’
m, s = PTY.open
m.write “a”
s.close
’
e$B$J$s$G=PNO$,$“$k$+$H$$$&$H!”$*$=$i$/e(B tty
e$B$N%(%3!<$@$m$&$H$$$&$3$H$G!"e(B
e$B%(%3!<$rM^@)$9$k$H%O%s%0$7$^$;$s!#e(B
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <termios.h>
int main(int argc, char *argv[])
{
int m, s;
char *slavedev;
struct termios t;
if ((m = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
perror(“posix_openpt”); exit(1); }
if (grantpt(m) == -1) { perror(“grantpt”); exit(1); }
if (unlockpt(m) == -1) { perror(“unlockpt”); exit(1); }
if ((slavedev = ptsname(m)) == NULL) { perror(“ptsname”); exit(1); }
if ((s = open(slavedev, O_RDWR|O_NOCTTY, 0)) == -1) {
perror(“open(slavedev)”); exit(1); }
if (tcgetattr(s, &t) == -1) { perror(“tcgetattr”); }
t.c_lflag &= ~(tcflag_t)(ECHO|ECHOE|ECHOK|ECHONL);
if (tcsetattr(s, TCSANOW, &t) == -1) { perror(“tcsetattr”); }
if (write(m, “a”, 1) == -1) { perror(“write”); exit(1); }
if (close(s) == -1) { perror(“close”); exit(1); }
return 0;
}
ruby e$B$J$i$3$&$G$9!#e(B
% ./ruby -rio/console -rpty -e ’
m, s = PTY.open
s.echo = false
m.write “a”
s.close
’
e$B$G$O!“e(Btest_script_from_stdin
e$B$G$b!”$H$$$&$H!"$=$3$,HyL/$G$9!#e(B
PTY.spawn e$B$Oe(B slave tty e$B$r65$($F$/$l$J$$$N$G!"e(B
slave tty e$B$Ke(B tcsetattr e$B$,$G$-$^$;$s!#e(B
FreeBSD e$B$@$H0J2<$N$h$&$Ke(B master e$BB&$Ke(B tcsetattr
e$B$rH/9T$7$F$bF0$/$s$G$9$,!“e(B
e$B$3$l$O%]!<%?%V%k$G$O$”$j$^$;$s!#e(B[ruby-list:28382]
% svn diff --diff-cmd diff -x -u test/ruby/test_rubyoptions.rb
Index: test/ruby/test_rubyoptions.rb
— test/ruby/test_rubyoptions.rb (revision 28906)
+++ test/ruby/test_rubyoptions.rb (working copy)
@@ -436,6 +436,7 @@
result = nil
s, w = IO.pipe
PTY.spawn(EnvUtil.rubybin, out: w) do |r, m|
@@ -446,6 +447,7 @@
assert_equal(“”, result, ‘[ruby-dev:37798]’)
s, w = IO.pipe
PTY.spawn(EnvUtil.rubybin, out: w) do |r, m|
e$B$3$N%F%9%H$G$O@)8fC<Kv$rJQ$($kI,MW$O$J$$$H;W$&$N$G!"e(B
PTY.open e$B$r;H$C$F=q$-D>$9$N$,$$$$$+$J$!!#e(B