|Anonymous | Login||2023-12-07 17:34 UTC|
|Main | My View | View Issues | Change Log | Docs|
|Viewing Issue Simple Details|
|ID||Category||Severity||Type||Date Submitted||Last Update|
|0000236||[1003.1(2008)/Issue 7] Shell and Utilities||Comment||Omission||2010-04-01 09:34||2010-05-06 15:12|
|Organization||The Open Group|
|Final Accepted Text|
|Summary||0000236: additional sh -c example that uses exec|
It would be useful to show an example of sh -c that uses exec
to avoid an extra process.
After example 1 insert a new example 2:
2. As example 1, but with the shell being replaced by cat instead of creating a new process for cat: sh -c "exec cat myfile"
Renumber the current example 2 to be 3.
|Tags||No tags attached.|
David Korn notes:
This is historical practice and a rather important optimization.
The system(string) function invokes sh -c string and is often
called with a string that is just a simple command. The performace
would be impaired if this caused two forks() rather than just one.
However, there are many circumstances where the optimization should
not be allowed since it would affect the behavior of a script.
For example, if the user has set a trap on EXIT, the last command
cannot exec since this would prevent the trap from taking place.
Note, that the script writer can always prevent the optimization by
to the end of the script.
With at least ksh88 and ksh93 (and I suspect others),
sh -c 'exec cat myfile'
will not save a process since the shell will recognized that this is
the last process and then exec cat without forking.
Moreover, if cat is implemented as a builtin, it will be slower
sh -c 'cat myfile'
In fact, I am unaware of any case where exec will save a process
creation. If I could think of one, I would look at how to
detect this without exec.
|2010-04-01 09:34||geoffclare||New Issue|
|2010-04-01 09:34||geoffclare||Status||New => Under Review|
|2010-04-01 09:34||geoffclare||Assigned To||=> ajosey|
|2010-04-01 09:34||geoffclare||Name||=> Geoff Clare|
|2010-04-01 09:34||geoffclare||Organization||=> The Open Group|
|2010-04-01 09:34||geoffclare||Section||=> sh|
|2010-04-01 09:34||geoffclare||Page Number||=> 3177|
|2010-04-01 09:34||geoffclare||Line Number||=> 105795|
|2010-04-01 09:34||geoffclare||Interp Status||=> ---|
|2010-05-06 15:12||msbrown||Note Added: 0000414|
|2010-05-06 15:12||msbrown||Status||Under Review => Resolved|
|2010-05-06 15:12||msbrown||Resolution||Open => Rejected|
|Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group|