pid_t pid = fork();
if(pid == -1){
//fork failed
}else if(pid == 0){
//I am the child
exec(...)
}else{
//I Am the parent
waitpid(pid, ...);
}
exec
execl( path, arg, … )
,execute the file in current directoryexeclp( file, arg, … )
, executes a file only searching in the pathexecle( path, arg, …, envp[])
, execute the file in path + environment settingsexecv( path, argv[])
, execute the file in current directoryexecvp( file, argv[])
, execute the file in the path onlyexecvpe( file, argv[]), envp[])
// environment setting./time <command> <args> ...
sleep 2
struct timespec
time_t tv_sec
;long tv_nsec
;tv_sec = 10
, tv_nsec = 992300000
-> 10.9923 sec
int clock_gettime(clockid_t, timespec *)
;
clockid_t
: should use CLOCK_MONOTONIC in this lab./env [key=val1] [key2=val1] ... -- cmd [args] ..
./env TZ=EST5EDT -- date
- execute date under enviornment TZ=EST5EDT./env TEMP=EST5EDT TZ=%TEMP -- date
- why is this the same as above?int setenv(const char* name, const char* value,
int overwrite)
char *getenv(const char *name)
%notation
in a string