Skip to content

Commit 85fa870

Browse files
treyharriszoffixznet
authored andcommitted
5to6: Add caution about exec workarounds (#1288)
"shell and exit" are poor substitutes for exec in some common situations. Add language to 5to6-perlfunc to explain these situations and suggest NativeCall if they pertain. Also note that most Unixes have no single "exec" function exactly (Perl 5 automagically dispatches the right one for the situation).
1 parent 1d65685 commit 85fa870

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

doc/Language/5to6-perlfunc.pod6

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,21 @@ Nothing in Perl 6 exactly replicates the Perl 5 C<exec>. C<shell> and
394394
C<run> are similar to Perl 5's C<system>, but C<exec>'s behavior of not
395395
returning after executing a system command would have to be emulated by
396396
something like C<shell($command);exit();> or possibly C<exit
397-
shell($command);>
397+
shell($command);>.
398+
399+
Neither of these workarounds have the behavior (on Unix-like systems)
400+
of I<replacing> your Perl program's process with the new program;
401+
notably, they will not work for the practice in some long-running
402+
daemons of periodically "re-execing themselves" to reset their state
403+
or force operating-system cleanup. Nor will they serve C<exec>'s
404+
function of returning stale resources to the operating system.
405+
406+
If you want C<exec> for these behaviors, you can use an C<exec*>
407+
function via the C<NativeCall> interface. Consult your operating
408+
system manual pages for C<exec> (or other similarly-named calls such
409+
as C<execl>, C<execv>, C<execvp>, or C<execvpe>). (Beware: these
410+
calls are not generally portable between Unix-like opearitng system
411+
families.)
398412
399413
=head2 exists
400414

0 commit comments

Comments
 (0)