-
Notifications
You must be signed in to change notification settings - Fork 0
/
execve.html
1200 lines (888 loc) · 33 KB
/
execve.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:25:42 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>EXECVE</title>
</head>
<body>
<h1 align="center">EXECVE</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#EXAMPLE">EXAMPLE</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">execve -
execute program</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<unistd.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
execve(const char *</b><i>pathname</i><b>, char *const</b>
<i>argv</i><b>[], <br>
char *const</b> <i>envp</i><b>[]);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>execve</b>()
executes the program referred to by <i>pathname</i>. This
causes the program that is currently being run by the
calling process to be replaced with a new program, with
newly initialized stack, heap, and (initialized and
uninitialized) data segments.</p>
<p style="margin-left:11%; margin-top: 1em"><i>pathname</i>
must be either a binary executable, or a script starting
with a line of the form:</p>
<p style="margin-left:17%; margin-top: 1em"><b>#!</b><i>interpreter</i>
[optional-arg]</p>
<p style="margin-left:11%; margin-top: 1em">For details of
the latter case, see "Interpreter scripts"
below.</p>
<p style="margin-left:11%; margin-top: 1em"><i>argv</i> is
an array of argument strings passed to the new program. By
convention, the first of these strings (i.e.,
<i>argv[0]</i>) should contain the filename associated with
the file being executed. <i>envp</i> is an array of strings,
conventionally of the form <b>key=value</b>, which are
passed as environment to the new program. The <i>argv</i>
and <i>envp</i> arrays must each include a null pointer at
the end of the array.</p>
<p style="margin-left:11%; margin-top: 1em">The argument
vector and environment can be accessed by the called
program’s main function, when it is defined as:</p>
<p style="margin-left:17%; margin-top: 1em">int main(int
argc, char *argv[], char *envp[])</p>
<p style="margin-left:11%; margin-top: 1em">Note, however,
that the use of a third argument to the main function is not
specified in POSIX.1; according to POSIX.1, the environment
should be accessed via the external variable
<b>environ</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em"><b>execve</b>()
does not return on success, and the text, initialized data,
uninitialized data (bss), and stack of the calling process
are overwritten according to the contents of the newly
loaded program.</p>
<p style="margin-left:11%; margin-top: 1em">If the current
program is being ptraced, a <b>SIGTRAP</b> signal is sent to
it after a successful <b>execve</b>().</p>
<p style="margin-left:11%; margin-top: 1em">If the
set-user-ID bit is set on the program file referred to by
<i>pathname</i>, then the effective user ID of the calling
process is changed to that of the owner of the program file.
Similarly, when the set-group-ID bit of the program file is
set the effective group ID of the calling process is set to
the group of the program file.</p>
<p style="margin-left:11%; margin-top: 1em">The
aforementioned transformations of the effective IDs are
<i>not</i> performed (i.e., the set-user-ID and set-group-ID
bits are ignored) if any of the following is true:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>the <i>no_new_privs</i> attribute is set for the calling
thread (see <b>prctl</b>(2));</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>the underlying filesystem is mounted <i>nosuid</i> (the
<b>MS_NOSUID</b> flag for <b>mount</b>(2)); or</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>the calling process is being ptraced.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The
capabilities of the program file (see
<b>capabilities</b>(7)) are also ignored if any of the above
are true.</p>
<p style="margin-left:11%; margin-top: 1em">The effective
user ID of the process is copied to the saved set-user-ID;
similarly, the effective group ID is copied to the saved
set-group-ID. This copying takes place after any effective
ID changes that occur because of the set-user-ID and
set-group-ID mode bits.</p>
<p style="margin-left:11%; margin-top: 1em">The
process’s real UID and real GID, as well its
supplementary group IDs, are unchanged by a call to
<b>execve</b>().</p>
<p style="margin-left:11%; margin-top: 1em">If the
executable is an a.out dynamically linked binary executable
containing shared-library stubs, the Linux dynamic linker
<b>ld.so</b>(8) is called at the start of execution to bring
needed shared objects into memory and link the executable
with them.</p>
<p style="margin-left:11%; margin-top: 1em">If the
executable is a dynamically linked ELF executable, the
interpreter named in the PT_INTERP segment is used to load
the needed shared objects. This interpreter is typically
<i>/lib/ld-linux.so.2</i> for binaries linked with glibc
(see <b>ld-linux.so</b>(8)).</p>
<p style="margin-left:11%; margin-top: 1em">All process
attributes are preserved during an <b>execve</b>(), except
the following:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em">*</p></td>
<td width="3%"></td>
<td width="85%">
<p style="margin-top: 1em">The dispositions of any signals
that are being caught are reset to the default
(<b>signal</b>(7)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Any alternate signal stack is not preserved
(<b>sigaltstack</b>(2)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Memory mappings are not preserved (<b>mmap</b>(2)).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Attached System V shared memory segments are
detached (<b>shmat</b>(2)).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>POSIX shared memory regions are unmapped
(<b>shm_open</b>(3)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Open POSIX message queue descriptors are closed
(<b>mq_overview</b>(7)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Any open POSIX named semaphores are closed
(<b>sem_overview</b>(7)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>POSIX timers are not preserved
(<b>timer_create</b>(2)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Any open directory streams are closed
(<b>opendir</b>(3)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Memory locks are not preserved (<b>mlock</b>(2),
<b>mlockall</b>(2)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Exit handlers are not preserved (<b>atexit</b>(3),
<b>on_exit</b>(3)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The floating-point environment is reset to the default
(see <b>fenv</b>(3)).</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The process
attributes in the preceding list are all specified in
POSIX.1. The following Linux-specific process attributes are
also not preserved during an <b>execve</b>():</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em">*</p></td>
<td width="3%"></td>
<td width="85%">
<p style="margin-top: 1em">The <b>prctl</b>(2)
<b>PR_SET_DUMPABLE</b> flag is set, unless a set-user-ID or
set-group ID program is being executed, in which case it is
cleared.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The <b>prctl</b>(2) <b>PR_SET_KEEPCAPS</b> flag is
cleared.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>(Since Linux 2.4.36 / 2.6.23) If a set-user-ID or
set-group-ID program is being executed, then the parent
death signal set by <b>prctl</b>(2) <b>PR_SET_PDEATHSIG</b>
flag is cleared.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The process name, as set by <b>prctl</b>(2)
<b>PR_SET_NAME</b> (and displayed by <i>ps -o
comm</i>), is reset to the name of the new executable
file.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The <b>SECBIT_KEEP_CAPS</b> <i>securebits</i> flag is
cleared. See <b>capabilities</b>(7).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The termination signal is reset to <b>SIGCHLD</b> (see
<b>clone</b>(2)).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The file descriptor table is unshared, undoing the
effect of the <b>CLONE_FILES</b> flag of
<b>clone</b>(2).</p> </td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Note the
following further points:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em">*</p></td>
<td width="3%"></td>
<td width="85%">
<p style="margin-top: 1em">All threads other than the
calling thread are destroyed during an <b>execve</b>().
Mutexes, condition variables, and other pthreads objects are
not preserved.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>The equivalent of <i>setlocale(LC_ALL,
"C")</i> is executed at program start-up.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>POSIX.1 specifies that the dispositions of any signals
that are ignored or set to the default are left unchanged.
POSIX.1 specifies one exception: if <b>SIGCHLD</b> is being
ignored, then an implementation may leave the disposition
unchanged or reset it to the default; Linux does the
former.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Any outstanding asynchronous I/O operations are canceled
(<b>aio_read</b>(3), <b>aio_write</b>(3)).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>For the handling of capabilities during <b>execve</b>(),
see <b>capabilities</b>(7).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>By default, file descriptors remain open across an
<b>execve</b>(). File descriptors that are marked
close-on-exec are closed; see the description of
<b>FD_CLOEXEC</b> in <b>fcntl</b>(2). (If a file descriptor
is closed, this will cause the release of all record locks
obtained on the underlying file by this process. See
<b>fcntl</b>(2) for details.) POSIX.1 says that if file
descriptors 0, 1, and 2 would otherwise be closed after a
successful <b>execve</b>(), and the process would gain
privilege because the set-user-ID or set-group_ID mode bit
was set on the executed file, then the system may open an
unspecified file for each of these file descriptors. As a
general principle, no portable program, whether privileged
or not, can assume that these three file descriptors will
remain closed across an <b>execve</b>().</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em"><b>Interpreter
scripts</b> <br>
An interpreter script is a text file that has execute
permission enabled and whose first line is of the form:</p>
<p style="margin-left:17%; margin-top: 1em"><b>#!</b><i>interpreter</i>
[optional-arg]</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>interpreter</i> must be a valid pathname for an
executable file.</p>
<p style="margin-left:11%; margin-top: 1em">If the
<i>pathname</i> argument of <b>execve</b>() specifies an
interpreter script, then <i>interpreter</i> will be invoked
with the following arguments:</p>
<p style="margin-left:17%; margin-top: 1em"><i>interpreter</i>
[optional-arg] <i>pathname</i> arg...</p>
<p style="margin-left:11%; margin-top: 1em">where
<i>pathname</i> is the absolute pathname of the file
specified as the first argument of <b>execve</b>(), and
<i>arg...</i> is the series of words pointed to by the
<i>argv</i> argument of <b>execve</b>(), starting at
<i>argv</i>[1]. Note that there is no way to get the
<i>argv[0]</i> that was passed to the <b>execve</b>()
call.</p>
<p style="margin-left:11%; margin-top: 1em">For portable
use, <i>optional-arg</i> should either be absent, or be
specified as a single word (i.e., it should not contain
white space); see NOTES below.</p>
<p style="margin-left:11%; margin-top: 1em">Since Linux
2.6.28, the kernel permits the interpreter of a script to
itself be a script. This permission is recursive, up to a
limit of four recursions, so that the interpreter may be a
script which is interpreted by a script, and so on.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Limits on
size of arguments and environment</b> <br>
Most UNIX implementations impose some limit on the total
size of the command-line argument (<i>argv</i>) and
environment (<i>envp</i>) strings that may be passed to a
new program. POSIX.1 allows an implementation to advertise
this limit using the <b>ARG_MAX</b> constant (either defined
in <i><limits.h></i> or available at run time using
the call <i>sysconf(_SC_ARG_MAX)</i>).</p>
<p style="margin-left:11%; margin-top: 1em">On Linux prior
to kernel 2.6.23, the memory used to store the environment
and argument strings was limited to 32 pages (defined by the
kernel constant <b>MAX_ARG_PAGES</b>). On architectures with
a 4-kB page size, this yields a maximum size of
128 kB.</p>
<p style="margin-left:11%; margin-top: 1em">On kernel
2.6.23 and later, most architectures support a size limit
derived from the soft <b>RLIMIT_STACK</b> resource limit
(see <b>getrlimit</b>(2)) that is in force at the time of
the <b>execve</b>() call. (Architectures with no memory
management unit are excepted: they maintain the limit that
was in effect before kernel 2.6.23.) This change allows
programs to have a much larger argument and/or environment
list. For these architectures, the total size is limited to
1/4 of the allowed stack size. (Imposing the 1/4-limit
ensures that the new program always has some stack space.)
Additionally, the total size is limited to 3/4 of the value
of the kernel constant <b>_STK_LIM</b> (8 Mibibytes). Since
Linux 2.6.25, the kernel also places a floor of 32 pages on
this size limit, so that, even when <b>RLIMIT_STACK</b> is
set very low, applications are guaranteed to have at least
as much argument and environment space as was provided by
Linux 2.6.23 and earlier. (This guarantee was not provided
in Linux 2.6.23 and 2.6.24.) Additionally, the limit per
string is 32 pages (the kernel constant
<b>MAX_ARG_STRLEN</b>), and the maximum number of strings is
0x7FFFFFFF.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>execve</b>() does not return, on error -1 is returned,
and <i>errno</i> is set appropriately.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>E2BIG</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The total number of bytes in the
environment (<i>envp</i>) and argument list (<i>argv</i>) is
too large.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Search permission is denied on a component of the path
prefix of <i>pathname</i> or the name of a script
interpreter. (See also <b>path_resolution</b>(7).)</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The file or a script interpreter is not a regular
file.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Execute permission is denied for the file or a script or
ELF interpreter.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The filesystem is mounted <i>noexec</i>.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>EAGAIN</b> (since Linux
3.1)</p>
<p style="margin-left:22%;">Having changed its real UID
using one of the <b>set*uid</b>() calls, the caller
was—and is now still—above its
<b>RLIMIT_NPROC</b> resource limit (see
<b>setrlimit</b>(2)). For a more detailed explanation of
this error, see NOTES.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EFAULT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>pathname</i> or one of the pointers in the vectors
<i>argv</i> or <i>envp</i> points outside your accessible
address space.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An ELF executable had more than one PT_INTERP segment
(i.e., tried to name more than one interpreter).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EIO</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An I/O error occurred.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EISDIR</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An ELF interpreter was a directory.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ELIBBAD</b></p>
<p style="margin-left:22%;">An ELF interpreter was not in a
recognized format.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ELOOP</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Too many symbolic links were encountered in resolving
<i>pathname</i> or the name of a script or ELF
interpreter.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ELOOP</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The maximum recursion limit was reached during recursive
script interpretation (see "Interpreter scripts",
above). Before Linux 3.8, the error produced for this case
was <b>ENOEXEC</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EMFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The per-process limit on the number of open file
descriptors has been reached.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENAMETOOLONG</b></p>
<p style="margin-left:22%;"><i>pathname</i> is too
long.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The system-wide limit on the total number of open files
has been reached.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOENT</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The file <i>pathname</i> or a script or ELF interpreter
does not exist, or a shared library needed for the file or
interpreter cannot be found.</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENOEXEC</b></p>
<p style="margin-left:22%;">An executable is not in a
recognized format, is for the wrong architecture, or has
some other format error that means it cannot be
executed.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="63%">
<p>Insufficient kernel memory was available.</p></td>
<td width="15%">
</td></tr>
</table>
<p style="margin-left:11%;"><b>ENOTDIR</b></p>
<p style="margin-left:22%;">A component of the path prefix
of <i>pathname</i> or a script or ELF interpreter is not a
directory.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>The filesystem is mounted <i>nosuid</i>, the user is not
the superuser, and the file has the set-user-ID or
set-group-ID bit set.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>The process is being traced, the user is not the
superuser and the file has the set-user-ID or set-group-ID
bit set.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="7%">
<p><b>EPERM</b></p></td>
<td width="4%"></td>
<td width="78%">
<p>A "capability-dumb" applications would not
obtain the full set of permitted capabilities granted by the
executable file. See <b>capabilities</b>(7).</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ETXTBSY</b></p>
<p style="margin-left:22%;">The specified executable was
open for writing by one or more processes.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008, SVr4, 4.3BSD. POSIX does not document the #!
behavior, but it exists (with some variations) on other UNIX
systems.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">One sometimes
sees <b>execve</b>() (and the related functions described in
<b>exec</b>(3)) described as "executing a <i>new</i>
process" (or similar). This is a highly misleading
description: there is no new process; many attributes of the
calling process remain unchanged (in particular, its PID).
All that <b>execve</b>(2) does is arrange for an existing
process (the calling process) to execute a new program.</p>
<p style="margin-left:11%; margin-top: 1em">Set-user-ID and
set-group-ID processes can not be <b>ptrace</b>(2)d.</p>
<p style="margin-left:11%; margin-top: 1em">The result of
mounting a filesystem <i>nosuid</i> varies across Linux
kernel versions: some will refuse execution of set-user-ID
and set-group-ID executables when this would give the user
powers they did not have already (and return <b>EPERM</b>),
some will just ignore the set-user-ID and set-group-ID bits
and <b>exec</b>() successfully.</p>
<p style="margin-left:11%; margin-top: 1em">On Linux,
<i>argv</i> and <i>envp</i> can be specified as NULL. In
both cases, this has the same effect as specifying the
argument as a pointer to a list containing a single null
pointer. <b>Do not take advantage of this nonstandard and
nonportable misfeature!</b> On many other UNIX systems,
specifying <i>argv</i> as NULL will result in an error
(<b>EFAULT</b>). <i>Some</i> other UNIX systems treat the
<i>envp==NULL</i> case the same as Linux.</p>
<p style="margin-left:11%; margin-top: 1em">POSIX.1 says
that values returned by <b>sysconf</b>(3) should be
invariant over the lifetime of a process. However, since
Linux 2.6.23, if the <b>RLIMIT_STACK</b> resource limit
changes, then the value reported by <b>_SC_ARG_MAX</b> will
also change, to reflect the fact that the limit on space for
holding command-line arguments and environment variables has
changed.</p>
<p style="margin-left:11%; margin-top: 1em">In most cases
where <b>execve</b>() fails, control returns to the original
executable image, and the caller of <b>execve</b>() can then
handle the error. However, in (rare) cases (typically caused
by resource exhaustion), failure may occur past the point of
no return: the original executable image has been torn down,
but the new image could not be completely built. In such
cases, the kernel kills the process with a <b>SIGKILL</b>
signal.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Interpreter
scripts</b> <br>
The kernel imposes a maximum length on the text that follows
the "#!" characters at the start of a script;