Reputation: 6255
I am using BSD style pty/tty pairs to implement running a sub shell. When the user exits the sub shell, how do I detect in the master process that this has occurred? I am using select(nfds, &read_fds, NULL, NULL, &timeout); with the master pty file descriptor set in the read_fds on the master side.
Upvotes: 1
Views: 673
Reputation: 6255
I've found the answer to this question by examining the telnetd source code found in the GNU inetutils package. In telnetd, they use a SIGCHLD handler like this:
int status;
pid_t pid = waitpid((pid_t)-1, &status, WNOHANG);
syslog (LOG_INFO, "child process %ld exited: %d",
(long) pid, WEXITSTATUS(status));
// do cleanup code
Upvotes: 2
Reputation: 48290
The subshell is typically created by a fork()
of some sort. The PID of the child is returned to the master, which can check (with waitpid()
, perhaps) if it's still running.
Upvotes: 3