]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/execve.2
execve.2: ffix
[thirdparty/man-pages.git] / man2 / execve.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\" and Copyright (c) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>:
29 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1999-11-12 by Urs Thuermann <urs@isnogud.escape.de>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" 2006-09-04 Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Added list of process attributes that are not preserved on exec().
34 .\" 2007-09-14 Ollie Wild <aaw@google.com>, mtk
35 .\" Add text describing limits on command-line arguments + environment
36 .\"
37 .TH EXECVE 2 2014-10-02 "Linux" "Linux Programmer's Manual"
38 .SH NAME
39 execve \- execute program
40 .SH SYNOPSIS
41 .B #include <unistd.h>
42 .sp
43 .BI "int execve(const char *" filename ", char *const " argv "[], "
44 .br
45 .BI " char *const " envp []);
46 .SH DESCRIPTION
47 .BR execve ()
48 executes the program pointed to by \fIfilename\fP.
49 \fIfilename\fP must be either a binary executable, or a script
50 starting with a line of the form:
51
52 .in +4n
53 .nf
54 \fB#!\fP \fIinterpreter \fP[optional-arg]
55 .fi
56 .in
57
58 For details of the latter case, see "Interpreter scripts" below.
59
60 \fIargv\fP is an array of argument strings passed to the new program.
61 By convention, the first of these strings should contain the filename
62 associated with the file being executed.
63 \fIenvp\fP is an array of strings, conventionally of the form
64 \fBkey=value\fP, which are passed as environment to the new program.
65 Both \fIargv\fP and \fIenvp\fP must be terminated by a null pointer.
66 The argument vector and environment can be accessed by the
67 called program's main function, when it is defined as:
68
69 .in +4n
70 .nf
71 int main(int argc, char *argv[], char *envp[])
72 .fi
73 .in
74
75 .BR execve ()
76 does not return on success, and the text, data, bss, and
77 stack of the calling process are overwritten by that of the program
78 loaded.
79
80 If the current program is being ptraced, a \fBSIGTRAP\fP is sent to it
81 after a successful
82 .BR execve ().
83
84 If the set-user-ID bit is set on the program file pointed to by
85 \fIfilename\fP,
86 and the underlying filesystem is not mounted
87 .I nosuid
88 (the
89 .B MS_NOSUID
90 flag for
91 .BR mount (2)),
92 and the calling process is not being ptraced,
93 then the effective user ID of the calling process is changed
94 to that of the owner of the program file.
95 Similarly, when the set-group-ID
96 bit of the program file is set the effective group ID of the calling
97 process is set to the group of the program file.
98
99 The effective user ID of the process is copied to the saved set-user-ID;
100 similarly, the effective group ID is copied to the saved set-group-ID.
101 This copying takes place after any effective ID changes that occur
102 because of the set-user-ID and set-group-ID permission bits.
103
104 If the executable is an a.out dynamically linked
105 binary executable containing
106 shared-library stubs, the Linux dynamic linker
107 .BR ld.so (8)
108 is called at the start of execution to bring
109 needed shared libraries into memory
110 and link the executable with them.
111
112 If the executable is a dynamically linked ELF executable, the
113 interpreter named in the PT_INTERP segment is used to load the needed
114 shared libraries.
115 This interpreter is typically
116 .I /lib/ld-linux.so.2
117 for binaries linked with glibc.
118
119 All process attributes are preserved during an
120 .BR execve (),
121 except the following:
122 .IP * 3
123 The dispositions of any signals that are being caught are
124 reset to the default
125 .RB ( signal (7)).
126 .IP *
127 Any alternate signal stack is not preserved
128 .RB ( sigaltstack (2)).
129 .IP *
130 Memory mappings are not preserved
131 .RB ( mmap (2)).
132 .IP *
133 Attached System\ V shared memory segments are detached
134 .RB ( shmat (2)).
135 .IP *
136 POSIX shared memory regions are unmapped
137 .RB ( shm_open (3)).
138 .IP *
139 Open POSIX message queue descriptors are closed
140 .RB ( mq_overview (7)).
141 .IP *
142 Any open POSIX named semaphores are closed
143 .RB ( sem_overview (7)).
144 .IP *
145 POSIX timers are not preserved
146 .RB ( timer_create (2)).
147 .IP *
148 Any open directory streams are closed
149 .RB ( opendir (3)).
150 .IP *
151 Memory locks are not preserved
152 .RB ( mlock (2),
153 .BR mlockall (2)).
154 .IP *
155 Exit handlers are not preserved
156 .RB ( atexit (3),
157 .BR on_exit (3)).
158 .IP *
159 The floating-point environment is reset to the default (see
160 .BR fenv (3)).
161 .PP
162 The process attributes in the preceding list are all specified
163 in POSIX.1-2001.
164 The following Linux-specific process attributes are also
165 not preserved during an
166 .BR execve ():
167 .IP * 3
168 The
169 .BR prctl (2)
170 .B PR_SET_DUMPABLE
171 flag is set,
172 unless a set-user-ID or set-group ID program is being executed,
173 in which case it is cleared.
174 .IP *
175 The
176 .BR prctl (2)
177 .B PR_SET_KEEPCAPS
178 flag is cleared.
179 .IP *
180 (Since Linux 2.4.36 / 2.6.23)
181 If a set-user-ID or set-group-ID program is being executed,
182 then the parent death signal set by
183 .BR prctl (2)
184 .B PR_SET_PDEATHSIG
185 flag is cleared.
186 .IP *
187 The process name, as set by
188 .BR prctl (2)
189 .B PR_SET_NAME
190 (and displayed by
191 .IR "ps\ \-o comm" ),
192 is reset to the name of the new executable file.
193 .IP *
194 The
195 .B SECBIT_KEEP_CAPS
196 .I securebits
197 flag is cleared.
198 See
199 .BR capabilities (7).
200 .IP *
201 The termination signal is reset to
202 .B SIGCHLD
203 (see
204 .BR clone (2)).
205 .PP
206 Note the following further points:
207 .IP * 3
208 All threads other than the calling thread are destroyed during an
209 .BR execve ().
210 Mutexes, condition variables, and other pthreads objects are not preserved.
211 .IP *
212 The equivalent of \fIsetlocale(LC_ALL, "C")\fP
213 is executed at program start-up.
214 .IP *
215 POSIX.1-2001 specifies that the dispositions of any signals that
216 are ignored or set to the default are left unchanged.
217 POSIX.1-2001 specifies one exception: if
218 .B SIGCHLD
219 is being ignored,
220 then an implementation may leave the disposition unchanged or
221 reset it to the default; Linux does the former.
222 .IP *
223 Any outstanding asynchronous I/O operations are canceled
224 .RB ( aio_read (3),
225 .BR aio_write (3)).
226 .IP *
227 For the handling of capabilities during
228 .BR execve (),
229 see
230 .BR capabilities (7).
231 .IP *
232 By default, file descriptors remain open across an
233 .BR execve ().
234 File descriptors that are marked close-on-exec are closed;
235 see the description of
236 .B FD_CLOEXEC
237 in
238 .BR fcntl (2).
239 (If a file descriptor is closed, this will cause the release
240 of all record locks obtained on the underlying file by this process.
241 See
242 .BR fcntl (2)
243 for details.)
244 POSIX.1-2001 says that if file descriptors 0, 1, and 2 would
245 otherwise be closed after a successful
246 .BR execve (),
247 and the process would gain privilege because the set-user_ID or
248 set-group_ID permission bit was set on the executed file,
249 then the system may open an unspecified file for each of these
250 file descriptors.
251 As a general principle, no portable program, whether privileged or not,
252 can assume that these three file descriptors will remain
253 closed across an
254 .BR execve ().
255 .\" On Linux it appears that these file descriptors are
256 .\" always open after an execve(), and it looks like
257 .\" Solaris 8 and FreeBSD 6.1 are the same. -- mtk, 30 Apr 2007
258 .SS Interpreter scripts
259 An interpreter script is a text file that has execute
260 permission enabled and whose first line is of the form:
261
262 .in +4n
263 .nf
264 \fB#!\fP \fIinterpreter \fP[optional-arg]
265 .fi
266 .in
267
268 The
269 .I interpreter
270 must be a valid pathname for an
271 executable which is not itself a script.
272 If the
273 .I filename
274 argument of
275 .BR execve ()
276 specifies an interpreter script, then
277 .I interpreter
278 will be invoked with the following arguments:
279
280 .in +4n
281 .nf
282 \fIinterpreter\fP [optional-arg] \fIfilename\fP arg...
283 .fi
284 .in
285
286 where
287 .I arg...
288 is the series of words pointed to by the
289 .I argv
290 argument of
291 .BR execve (),
292 starting at
293 .IR argv [1].
294
295 For portable use,
296 .I optional-arg
297 should either be absent, or be specified as a single word (i.e., it
298 should not contain white space); see NOTES below.
299 .SS Limits on size of arguments and environment
300 Most UNIX implementations impose some limit on the total size
301 of the command-line argument
302 .RI ( argv )
303 and environment
304 .RI ( envp )
305 strings that may be passed to a new program.
306 POSIX.1 allows an implementation to advertise this limit using the
307 .B ARG_MAX
308 constant (either defined in
309 .I <limits.h>
310 or available at run time using the call
311 .IR "sysconf(_SC_ARG_MAX)" ).
312
313 On Linux prior to kernel 2.6.23, the memory used to store the
314 environment and argument strings was limited to 32 pages
315 (defined by the kernel constant
316 .BR MAX_ARG_PAGES ).
317 On architectures with a 4-kB page size,
318 this yields a maximum size of 128 kB.
319
320 On kernel 2.6.23 and later, most architectures support a size limit
321 derived from the soft
322 .B RLIMIT_STACK
323 resource limit (see
324 .BR getrlimit (2))
325 that is in force at the time of the
326 .BR execve ()
327 call.
328 (Architectures with no memory management unit are excepted:
329 they maintain the limit that was in effect before kernel 2.6.23.)
330 This change allows programs to have a much larger
331 argument and/or environment list.
332 .\" For some background on the changes to ARG_MAX in kernels 2.6.23 and
333 .\" 2.6.25, see:
334 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=5786
335 .\" http://bugzilla.kernel.org/show_bug.cgi?id=10095
336 .\" http://thread.gmane.org/gmane.linux.kernel/646709/focus=648101,
337 .\" checked into 2.6.25 as commit a64e715fc74b1a7dcc5944f848acc38b2c4d4ee2.
338 For these architectures, the total size is limited to 1/4 of the allowed
339 stack size.
340 (Imposing the 1/4-limit
341 ensures that the new program always has some stack space.)
342 .\" Ollie: That doesn't include the lists of pointers, though,
343 .\" so the actual usage is a bit higher (1 pointer per argument).
344 Since Linux 2.6.25,
345 the kernel places a floor of 32 pages on this size limit,
346 so that, even when
347 .BR RLIMIT_STACK
348 is set very low,
349 applications are guaranteed to have at least as much argument and
350 environment space as was provided by Linux 2.6.23 and earlier.
351 (This guarantee was not provided in Linux 2.6.23 and 2.6.24.)
352 Additionally, the limit per string is 32 pages (the kernel constant
353 .BR MAX_ARG_STRLEN ),
354 and the maximum number of strings is 0x7FFFFFFF.
355 .SH RETURN VALUE
356 On success,
357 .BR execve ()
358 does not return, on error \-1 is returned, and
359 .I errno
360 is set appropriately.
361 .SH ERRORS
362 .TP
363 .B E2BIG
364 The total number of bytes in the environment
365 .RI ( envp )
366 and argument list
367 .RI ( argv )
368 is too large.
369 .TP
370 .B EACCES
371 Search permission is denied on a component of the path prefix of
372 .I filename
373 or the name of a script interpreter.
374 (See also
375 .BR path_resolution (7).)
376 .TP
377 .B EACCES
378 The file or a script interpreter is not a regular file.
379 .TP
380 .B EACCES
381 Execute permission is denied for the file or a script or ELF interpreter.
382 .TP
383 .B EACCES
384 The filesystem is mounted
385 .IR noexec .
386 .TP
387 .BR EAGAIN " (since Linux 3.1)"
388 .\" commit 72fa59970f8698023045ab0713d66f3f4f96945c
389 Having changed its real UID using one of the
390 .BR set*uid ()
391 calls, the caller was\(emand is now still\(emabove its
392 .BR RLIMIT_NPROC
393 resource limit (see
394 .BR setrlimit (2)).
395 For a more detailed explanation of this error, see NOTES.
396 .TP
397 .B EFAULT
398 .I filename
399 or one of the pointers in the vectors
400 .I argv
401 or
402 .I envp
403 points outside your accessible address space.
404 .TP
405 .B EINVAL
406 An ELF executable had more than one PT_INTERP segment (i.e., tried to
407 name more than one interpreter).
408 .TP
409 .B EIO
410 An I/O error occurred.
411 .TP
412 .B EISDIR
413 An ELF interpreter was a directory.
414 .TP
415 .B ELIBBAD
416 An ELF interpreter was not in a recognized format.
417 .TP
418 .B ELOOP
419 Too many symbolic links were encountered in resolving
420 .I filename
421 or the name of a script or ELF interpreter.
422 .TP
423 .B EMFILE
424 The process has the maximum number of files open.
425 .TP
426 .B ENAMETOOLONG
427 .I filename
428 is too long.
429 .TP
430 .B ENFILE
431 The system limit on the total number of open files has been reached.
432 .TP
433 .B ENOENT
434 The file
435 .I filename
436 or a script or ELF interpreter does not exist, or a shared library
437 needed for file or interpreter cannot be found.
438 .TP
439 .B ENOEXEC
440 An executable is not in a recognized format, is for the wrong
441 architecture, or has some other format error that means it cannot be
442 executed.
443 .TP
444 .B ENOMEM
445 Insufficient kernel memory was available.
446 .TP
447 .B ENOTDIR
448 A component of the path prefix of
449 .I filename
450 or a script or ELF interpreter is not a directory.
451 .TP
452 .B EPERM
453 The filesystem is mounted
454 .IR nosuid ,
455 the user is not the superuser,
456 and the file has the set-user-ID or set-group-ID bit set.
457 .TP
458 .B EPERM
459 The process is being traced, the user is not the superuser and the
460 file has the set-user-ID or set-group-ID bit set.
461 .TP
462 .B ETXTBSY
463 Executable was open for writing by one or more processes.
464 .SH CONFORMING TO
465 SVr4, 4.3BSD, POSIX.1-2001.
466 POSIX.1-2001 does not document the #! behavior
467 but is otherwise compatible.
468 .\" SVr4 documents additional error
469 .\" conditions EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP; POSIX does not
470 .\" document ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE, EINVAL,
471 .\" EISDIR or ELIBBAD error conditions.
472 .SH NOTES
473 Set-user-ID and set-group-ID processes can not be
474 .BR ptrace (2)d.
475
476 The result of mounting a filesystem
477 .I nosuid
478 varies across Linux kernel versions:
479 some will refuse execution of set-user-ID and set-group-ID
480 executables when this would
481 give the user powers she did not have already (and return
482 .BR EPERM ),
483 some will just ignore the set-user-ID and set-group-ID bits and
484 .BR exec ()
485 successfully.
486 On Linux,
487 .I argv
488 and
489 .I envp
490 can be specified as NULL.
491 In both cases, this has the same effect as specifying the argument
492 as a pointer to a list containing a single null pointer.
493 .B "Do not take advantage of this misfeature!"
494 It is nonstandard and nonportable:
495 on most other UNIX systems doing this will result in an error
496 .RB ( EFAULT ).
497 .\" e.g., EFAULT on Solaris 8 and FreeBSD 6.1; but
498 .\" HP-UX 11 is like Linux -- mtk, Apr 2007
499 .\" Bug filed 30 Apr 2007: http://bugzilla.kernel.org/show_bug.cgi?id=8408
500 .\" Bug rejected (because fix would constitute an ABI change).
501 .\"
502
503 POSIX.1-2001 says that values returned by
504 .BR sysconf (3)
505 should be invariant over the lifetime of a process.
506 However, since Linux 2.6.23, if the
507 .BR RLIMIT_STACK
508 resource limit changes, then the value reported by
509 .B _SC_ARG_MAX
510 will also change,
511 to reflect the fact that the limit on space for holding
512 command-line arguments and environment variables has changed.
513
514 In most cases where
515 .BR execve ()
516 fails, control returns to the original executable image,
517 and the caller of
518 .BR execve ()
519 can then handle the error.
520 However, in (rare) cases (typically caused by resource exhaustion),
521 failure may occur past the point of no return:
522 the original executable image has been torn down,
523 but the new image could not be completely built.
524 In such cases, the kernel kills the process with a
525 .BR SIGKILL
526 signal.
527 .\"
528 .SS Interpreter scripts
529 A maximum line length of 127 characters is allowed for the first line in
530 an interpreter scripts.
531
532 The semantics of the
533 .I optional-arg
534 argument of an interpreter script vary across implementations.
535 On Linux, the entire string following the
536 .I interpreter
537 name is passed as a single argument to the interpreter,
538 and this string can include white space.
539 However, behavior differs on some other systems.
540 Some systems
541 .\" e.g., Solaris 8
542 use the first white space to terminate
543 .IR optional-arg .
544 On some systems,
545 .\" e.g., FreeBSD before 6.0, but not FreeBSD 6.0 onward
546 an interpreter script can have multiple arguments,
547 and white spaces in
548 .I optional-arg
549 are used to delimit the arguments.
550
551 Linux ignores the set-user-ID and set-group-ID bits on scripts.
552 .\"
553 .\" .SH BUGS
554 .\" Some Linux versions have failed to check permissions on ELF
555 .\" interpreters. This is a security hole, because it allows users to
556 .\" open any file, such as a rewinding tape device, for reading. Some
557 .\" Linux versions have also had other security holes in
558 .\" .BR execve ()
559 .\" that could be exploited for denial of service by a suitably crafted
560 .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
561 .SS execve() and EAGAIN
562 A more detailed explanation of the
563 .BR EAGAIN
564 error that can occur (since Linux 3.1) when calling
565 .BR execve ()
566 is as follows.
567
568 The
569 .BR EAGAIN
570 error can occur when a
571 .I preceding
572 call to
573 .BR setuid (2),
574 .BR setreuid (2),
575 or
576 .BR setresuid (2)
577 caused the real user ID of the process to change,
578 and that change caused the process to exceed its
579 .BR RLIMIT_NPROC
580 resource limit (i.e., the number of processes belonging
581 to the new real UID exceeds the resource limit).
582 From Linux 2.6.0 to 3.0, this caused the
583 .BR set*uid ()
584 call to fail.
585 (Prior to 2.6,
586 .\" commit 909cc4ae86f3380152a18e2a3c44523893ee11c4
587 the resource limit was not imposed on processes that
588 changed their user IDs.)
589
590 Since Linux 3.1, the scenario just described no longer causes the
591 .BR set*uid ()
592 call to fail,
593 because it too often led to security holes where buggy applications
594 didn't check the return status and assumed
595 that\(emif the caller had root privileges\(emthe call would always succeed.
596 Instead, the
597 .BR set*uid ()
598 calls now successfully change the real UID,
599 but the kernel sets an internal flag, named
600 .BR PF_NPROC_EXCEEDED ,
601 to note that the
602 .BR RLIMIT_NPROC
603 resource limit has been exceeded.
604 If the
605 .BR PF_NPROC_EXCEEDED
606 flag is set and the resource limit is still
607 exceeded at the time of a subsequent
608 .BR execve ()
609 call, that call fails with the error
610 .BR EAGAIN .
611 This kernel logic ensures that the
612 .BR RLIMIT_NPROC
613 resource limit is still enforced for the
614 common privileged daemon workflow\(emnamely,
615 .BR fork (2)
616 +
617 .BR set*uid ()
618 +
619 .BR execve ().
620
621 If the resource limit was not still exceeded at the time of the
622 .BR execve ()
623 call
624 (because other processes belonging to this real UID terminated between the
625 .BR set*uid ()
626 call and the
627 .BR execve ()
628 call), then the
629 .BR execve ()
630 call succeeds and the kernel clears the
631 .BR PF_NPROC_EXCEEDED
632 process flag.
633 The flag is also cleared if a subsequent call to
634 .BR fork (2)
635 by this process succeeds.
636 .SS Historical
637 With UNIX\ V6, the argument list of an
638 .BR exec ()
639 call was ended by 0,
640 while the argument list of
641 .I main
642 was ended by \-1.
643 Thus, this argument list was not directly usable in a further
644 .BR exec ()
645 call.
646 Since UNIX\ V7, both are NULL.
647 .\"
648 .\" .SH BUGS
649 .\" Some Linux versions have failed to check permissions on ELF
650 .\" interpreters. This is a security hole, because it allows users to
651 .\" open any file, such as a rewinding tape device, for reading. Some
652 .\" Linux versions have also had other security holes in
653 .\" .BR execve ()
654 .\" that could be exploited for denial of service by a suitably crafted
655 .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
656 .SH EXAMPLE
657 The following program is designed to be execed by the second program below.
658 It just echoes its command-line arguments, one per line.
659
660 .in +4n
661 .nf
662 /* myecho.c */
663
664 #include <stdio.h>
665 #include <stdlib.h>
666
667 int
668 main(int argc, char *argv[])
669 {
670 int j;
671
672 for (j = 0; j < argc; j++)
673 printf("argv[%d]: %s\\n", j, argv[j]);
674
675 exit(EXIT_SUCCESS);
676 }
677 .fi
678 .in
679
680 This program can be used to exec the program named in its command-line
681 argument:
682 .in +4n
683 .nf
684
685 /* execve.c */
686
687 #include <stdio.h>
688 #include <stdlib.h>
689 #include <unistd.h>
690
691 int
692 main(int argc, char *argv[])
693 {
694 char *newargv[] = { NULL, "hello", "world", NULL };
695 char *newenviron[] = { NULL };
696
697 if (argc != 2) {
698 fprintf(stderr, "Usage: %s <file\-to\-exec>\\n", argv[0]);
699 exit(EXIT_FAILURE);
700 }
701
702 newargv[0] = argv[1];
703
704 execve(argv[1], newargv, newenviron);
705 perror("execve"); /* execve() only returns on error */
706 exit(EXIT_FAILURE);
707 }
708 .fi
709 .in
710
711 We can use the second program to exec the first as follows:
712
713 .in +4n
714 .nf
715 .RB "$" " cc myecho.c \-o myecho"
716 .RB "$" " cc execve.c \-o execve"
717 .RB "$" " ./execve ./myecho"
718 argv[0]: ./myecho
719 argv[1]: hello
720 argv[2]: world
721 .fi
722 .in
723
724 We can also use these programs to demonstrate the use of a script
725 interpreter.
726 To do this we create a script whose "interpreter" is our
727 .I myecho
728 program:
729
730 .in +4n
731 .nf
732 .RB "$" " cat > script"
733 .B #!./myecho script-arg
734 .B ^D
735 .RB "$" " chmod +x script"
736 .fi
737 .in
738
739 We can then use our program to exec the script:
740
741 .in +4n
742 .nf
743 .RB "$" " ./execve ./script"
744 argv[0]: ./myecho
745 argv[1]: script-arg
746 argv[2]: ./script
747 argv[3]: hello
748 argv[4]: world
749 .fi
750 .in
751 .SH SEE ALSO
752 .BR chmod (2),
753 .BR fork (2),
754 .BR ptrace (2),
755 .BR execl (3),
756 .BR fexecve (3),
757 .BR getopt (3),
758 .BR credentials (7),
759 .BR environ (7),
760 .BR path_resolution (7),
761 .BR ld.so (8)