mysqld_safe holding open a pty/tty on FreeBSD (7.x and 8.x)
Jeremy Chadwick
freebsd at jdc.parodius.com
Thu Sep 30 06:51:54 UTC 2010
Something interesting I've come across which happens on both RELENG_7
and RELENG_8 (indicating it's not a problem with the older tty code or
the newer pty/pts code), and it's reproducible on Linux (sort of...).
mysqld_safe appears to hold a pty/tty open even after the process has
been backgrounded. I can understand how/why this might occur, just not
in this particular case.
I had a colleague test the situation on his Linux machine. He was able
to confirm that:
1) "mysqld_safe > /dev/null 2>&1 &" never released the tty
2) "nohup mysqld_safe > /dev/null 2>&1 &" did release the tty
With regards to test #1, looking in /proc/{pid}/fd showed that STDIN was
being held open. I recommended he point STDIN to /dev/null as so:
"mysqld_safe < /dev/null > /dev/null 2>&1 &"
Which also solved the problem.
On FreeBSD it's a different story. Below, mysql-server was started as
root on pts/1. The open file descriptors all point to /dev/null, so I'm
not sure why the pty/tty is being held open.
icarus# ps -aux -U mysql
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
mysql 10078 0.2 0.3 35100 11032 1 S 11:38PM 0:00.02 [mysqld]
mysql 9997 0.0 0.0 8228 1592 1 S 11:38PM 0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/storage/mys
icarus# procstat -f 9997
PID COMM FD T V FLAGS REF OFFSET PRO NAME
9997 sh cwd v d -------- - - - /root
9997 sh root v d -------- - - - /
9997 sh 0 v c r------- 1 0 - /dev/null
9997 sh 1 v c -w------ 2 0 - /dev/null
9997 sh 2 v c -w------ 2 0 - /dev/null
icarus# procstat -f 10078
PID COMM FD T V FLAGS REF OFFSET PRO NAME
10078 mysqld cwd v d -------- - - - /storage/mysql
10078 mysqld root v d -------- - - - /
10078 mysqld 0 v c r------- 1 0 - /dev/null
10078 mysqld 1 v r rwa----- 1 32048 - /storage/mysql/icarus.home.lan.err
10078 mysqld 2 v r rwa----- 1 32380 - /storage/mysql/icarus.home.lan.err
At this point I log out of pts/1 and log back in to the machine (which
sticks me on pts/2 as a result of the problem). Looking again, we see:
icarus# ps -aux -U mysql
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
mysql 9997 0.0 0.0 8228 1592 1- I 11:38PM 0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/storage/mys
mysql 10078 0.0 0.3 35100 11032 1- I 11:38PM 0:00.02 [mysqld]
With absolutely no change in procstat output relevant to fds 0/1/2.
Yet pts/1 still appears held open by something:
icarus# ls -l /dev/pts
total 0
crw--w---- 1 jdc tty 0, 116 Sep 29 23:44 0
crw-rw-rw- 1 root wheel 0, 115 Sep 29 23:41 1
crw--w---- 1 jdc tty 0, 117 Sep 29 23:44 2
fstat also shows no indication of anything using pts/1:
icarus# fstat /dev/pts/1
USER CMD PID FD MOUNT INUM MODE SZ|DV R/W NAME
icarus# fstat | grep pts/1
icarus#
Ideas?
--
| Jeremy Chadwick jdc at parodius.com |
| Parodius Networking http://www.parodius.com/ |
| UNIX Systems Administrator Mountain View, CA, USA |
| Making life hard for others since 1977. PGP: 4BD6C0CB |
More information about the freebsd-stable
mailing list