200 lines · 4.4 KB · Text
RawDownload
.TH EXEC 2.SH NAMEexec, execl, _privates, _nprivates, _tos \- execute a file.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.nf.Bvoid* exec(char *name, char* argv[]).PP.Bvoid* execl(char *name, ...).PP.Bvoid	**_privates;.PP.Bint	_nprivates;.PP.B#include <tos.h>.PP.ft Ltypedef struct Tos Tos;struct Tos {    struct { ... } prof;    /* profiling data */    uvlong  cyclefreq;      /* cycle clock frequency */    vlong   kcycles;        /* kernel cycles */    vlong   pcycles;        /* process cycles (kernel + user) */    ulong   pid;            /* process id */    ulong   clock;          /* profiling clock */    /* top of stack is here */};.PP.Bextern Tos *_tos;.fi.SH DESCRIPTION.I Execand.I execloverlay the calling process with the named file, thentransfer to the entry point of the image of the file..PP.I Namepoints to the name of the fileto be executed; it must not be a directory, and the permissionsmust allow the current user to execute it(see.IR stat (2)).It should also be a valid binary image, as defined in the.IR a.out (6)for the current machine architecture,or a shell script(see.IR rc (1)).The first line of ashell script must begin with.L #!followed by the name of the program to interpret the fileand any initial arguments to that program, for example.IP.EX#!/bin/rcls | mc.EE.PPWhen a C program is executed,it is called as follows:.IP.EXvoid main(int argc, char *argv[]).EE.PP.I Argvis a copy of the array of argument pointers passed to.IR exec ;that array must end in a null pointer, and.I argcis the number of elements before the null pointer.By convention, the first argument should be the name ofthe program to be executed..I Execlis like.I execexcept that.I argvwill be an array of the parameters that follow.I namein the call.  The last argument to.I execlmust be a null pointer..PPFor a file beginning.BR #! ,the arguments passed to the program.RB ( /bin/rcin the example above) will be the name of the file beingexecuted, any arguments on the.B #!line, the name of the file again,and finally the second and subsequent arguments given to the original.I execcall.The result honors the two conventions of a program accepting as argumenta file to be interpreted and.B argv[0]naming the file beingexecuted..PPMost attributes of the calling process are carriedinto the result; in particular,files remain open across.I exec(except those opened with.B OCEXECOR'dinto the open mode; see.IR open (2));and the working directory and environment(see.IR env (3))remain the same.However, a newly.I exec'edprocess has no notification handler(see.IR notify (2))..PPThe global cell.B _privatespoints to an array of.B _nprivateselements of per-process private data.This storage is private for each process, even if the processes share data segments..PPWhen the new program begins, the global pointer.B _tosis set to the address of a structurethat holds informationallowing accurate time keeping and clock reading in user space.These data are updated by the kernel during of the life of the process,including across.IR rfork sand.IR exec s.If there is a user-space accessible fast clock (a processorcycle counter),.B cyclefreqwill be set to its frequency in Hz..B Kcycles.RB ( pcycles )counts the number of cycles this process has spent in kernel mode(kernel and user mode)..B Pidis the current process's id..B Clockis the user-profiling clock (see.IR prof (1)).Its time is measured in milliseconds but is updated ata system-dependent lower rate.This clock is typically used by the profiler but is availableto all programs..PPThe above conventions apply to C programs; the raw systeminterface to the new image is as follows:the word pointed to by the stack pointer is.BR argc ;the words beyond that are the zeroth and subsequent elementsof.BR argv ,followed by a terminating null pointer; andthe return register (e.g..B R0on the 68020) contains the address of the clock information..SH SOURCE.B /sys/src/libc/9syscall.br.B /sys/src/libc/port/execl.c.SH SEE ALSO.IR prof (1),.IR intro (2),.IR stat (2).SH DIAGNOSTICSIf these functions fail, they return and set.IR errstr .There can be no return to the calling process from a successful.I execor.IR execl ;the calling image is lost..SH BUGSThere is a large but finite limit on the size of an argment list,typically around 409,600 bytes.The kernel constant.B TSTKSIZcontrols this.