Date: Tue, 19 Jun 2007 18:30:13 GMT From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/113860: sh: shell is still running when using `sh -c' Message-ID: <200706191830.l5JIUDud077546@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/113860; it has been noted by GNATS. From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-bugs@FreeBSD.ORG, Ed Schouten <ed@fxq.nl>, bug-followup@FreeBSD.ORG Cc: Subject: Re: bin/113860: sh: shell is still running when using `sh -c' Date: Tue, 19 Jun 2007 20:29:36 +0200 (CEST) Ed Schouten wrote: > Some bloated shell from GNU immediately shuts down the shell when using > `sh -c'. This means that: > > sh -c 'sleep 10' > > only keeps a sleep(1) process running for 10 seconds; the shell is > closed immediately. That's only possible for simple cases, i.e. when a single external command is used. In all other cases, the shell process has to be kept, e.g.: sh -c 'sleep 10; echo foobar' In that case the shell process has to stay and wait for the command to finish. > FreeBSD's sh doesn't. This means that all applications that use > system(3) or just execve(2) /bin/sh leave shells running around. Which is not a big deal. Those shell processes are quite cheap. Most of the RSS that you see in top is shared between processes, so the RAM consumption is negligible. If you want to avoid the shell process anyway, a simple workaround is to preped "exec": sh -c 'exec sleep 10' In that case the shell will exec() the program directly, instead of fork() and waiting for it to finish. Actually that's exactly what that "bloated shell from GNU" does automatically (prepending "exec" internally). Implementing that automatic behaviour in FreeBSD's /bin/sh is not trivial, because you have to find out first if it is possible for the given command line or not. Apart from that I'm not sure if it is desirable to have such a "feature". Personally I believe that the shell should do what I tell it to do. That is, when I want it to use "exec", I write "exec". If I don't want it, I don't write it. I would be somewhat surprised if it used "exec" when I don't instruct it to do so. It might be regarded as a POLA violation, but it's probably a matter of opinion. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd $ dd if=/dev/urandom of=test.pl count=1 $ file test.pl test.pl: perl script text executable
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706191830.l5JIUDud077546>