UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Processes
  • » Any good way to monitor pty usage on MacOS/X?

#1 2008-06-18 11:54 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Any good way to monitor pty usage on MacOS/X?

Hi all,

I've written a program that calls forkpty() to launch multiple child processes (usually a few dozen at a time), and then it interacts them via their stdin/stdout streams.

This program works fine under Linux, and usually works fine under MacOS/X, except on one particular machine.  On this one machine, forkpty() will work correctly for a while after boot (say, a few hours or days), and then it will start to misbehave.  When the fault occurs, the forkpty() call will simply never return, hanging my parent process.

I suspect that this misbehavior is occurring because of a resource leak of some sort.... my guess in particular is that some program (possibly mine but more likely something else that is running on this machine, since my program isn't always running) is slowly tying up all the available pty's, until there are few or none left, at which point forkpty() becomes unreliable.

I should note that when the computer is in this state, the Terminal.app program itself will sometimes freeze/hang/pinwheel when opening a new window... and if I force-kill it, the crash report shows that Terminal.app was stuck in a non-returning forkpty() call also.  So it's not only my program that is suffering from the forkpty() fault.

Anyway, the question is:  what is the best way to find out how many pty's are currently in use, and/or which programs are using them?  If I knew that information I could probably find the culprit fairly quickly... but I'm not sure how to do that.  Any hints?

Thanks,
Jeremy

Offline

#2 2008-06-19 12:48 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Any good way to monitor pty usage on MacOS/X?

I know nothing about macs, but perhaps lsof works?

Offline

#3 2008-06-19 04:38 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Any good way to monitor pty usage on MacOS/X?

Offline

#4 2008-06-19 06:56 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: Any good way to monitor pty usage on MacOS/X?

Just for the record.... lsof didn't seem to help here (the output of lsof didn't differ in any obvious way from a good system to the bad one).  However, after some trial and error, it appears that the DarwinPorts package is the distinguishing factor.  That is, the problem Mac had DarwinPorts installed, and the other (working Macs) did not; and disabling DarwinPorts seems to make the problems go away.  I still don't understand the exact mechanism though.

-Jeremy

Offline

#5 2008-06-19 08:46 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Any good way to monitor pty usage on MacOS/X?

Offline

  • Index
  • » Processes
  • » Any good way to monitor pty usage on MacOS/X?

Board footer

Powered by FluxBB