From: Tanaka Akira Date: 2009-04-25T12:10:59+09:00 Subject: [ruby-core:23309] Re: [Bug #1403] Process.daemon should do a double fork to avoid problems with controlling terminals In article <49f26316.8602be0a.1190.2d9f@mx.google.com>, Nobuyoshi Nakada writes: >> The second fork ensures that the process (the grandchild of the >> original process) is no longer a session leader and therefore can't >> acquire a controlling terminal by opening a tty device. > > Could you show concrete example? % ruby -v -rpty -e ' m, s = PTY.open Process.daemon(true,true) system("ps cj#{$$}") open(s.path) system("ps cj#{$$}") '; sleep 1 ruby 1.9.2dev (2009-03-13 trunk 22936) [i686-linux] PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 6153 6153 6153 ? -1 Rsl 1000 0:00 ruby PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 6153 6153 6153 pts/11 6153 Rs+ 1000 0:00 ruby This request means that 2nd TTY field should be "?" as 1st. fork after Process.daemon does that. % ruby -v -rpty -e ' m, s = PTY.open Process.daemon(true,true) exit if fork != nil system("ps cj#{$$}") open(s.path) system("ps cj#{$$}") '; sleep 1 ruby 1.9.2dev (2009-03-13 trunk 22936) [i686-linux] PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 6241 6238 6238 ? -1 Sl 1000 0:00 ruby PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 6241 6238 6238 ? -1 Sl 1000 0:00 ruby I'm not sure this is a bug of daemon() in glibc or not. [ruby-talk:111518] -- Tanaka Akira