X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: Excessive thrashing when popen()ing after a large malloc() Date: Wed, 15 Nov 2006 16:18:10 +0000 (UTC) Lines: 27 Message-ID: References: <4559D376 DOT 9030707 AT byu DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Eric Blake byu.net> writes: > > else > > sprintf(cmd, "sh -c '%s' %d>&-", program, pdes[1]) > > } > > pid = spawnl(_P_NOWAIT, _PATH_BSHELL, "sh", "-c", cmd, NULL); > > Why are you going through two levels of sh? That seems like a waste to > me; the whole idea of using spawn is to avoid a fork(), but when you > invoke "sh" "-c" "sh -c 'cmd'", you are right back to a fork. True, the > new invocation of sh uses less memory than the 1 GB process that invoked > popen, so less thrashing will occur, but your whole approach seems > fundamentally flawed if you are trying to use spawn to avoid a fork. You know, maybe a better approach to this would be to first implement posix_spawn() in cygwin, since that API seems like it would be possible to do the necessary fd manipulation in a spawned child process without the penalty of a full fork/exec. Then you could teach popen how to use posix_spawn when it is available, which is probably a patch more likely to be accepted in newlib, rather than your current idea of having to go through an intermediary sh invocation. But I do not have a copyright on file for cygwin contributions, so I am currently unable to work on contributing posix_spawn; you are at the mercy of someone willing and able to write such a patch. -- Eric Blake -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/