I'm using Mac (10.14.6), following quote is from man termios
:
When a controlling terminal becomes associated with a session, its foreground process group is set to the process group of the session leader.
To verify this, I opened a terminal window, ran sleep
command in the foreground, then opened another terminal windows and ran ps
:
$ ps -o pid,pgid,tpgid,sess,stat,command,tty
PID PGID TPGID SESS STAT COMMAND TTY
44606 44606 45006 0 S -bash ttys000
45006 45006 45006 0 S+ sleep 3000 ttys000
which shows foreground process group as 45006
, to get the session leader I wrote some C code using getsid
and getpgid
, then get following info:
pid: 45006 pgid: 45006 sid: 44605
pid: 44605 pgid: 44605 sid: 44605
the session leader is 44605
which is the login proc:
$ ps -o pid,pgid,tpgid,sess,stat,command,tty -p 44605
PID PGID TPGID SESS STAT COMMAND TTY
44605 44605 45006 0 Ss login -pfl mz /b ttys000
obviously the foreground proc group 45006
differs from session leader proc group 44605
, what am I missing? Thanks!