
pid_t pid = fork();
if(pid == -1){
//fork failed
}else if(pid == 0){
//I am the child
exec(...)
}else{
//I Am the parent
wait(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 [-n #] [key=val1,val2,...] [key2=val1,val2,...] ... -- cmd [args] .../env -n 4 TZ=EST5EDT,CST6CDT,MST7MDT,PST8PDT -- date - execute date under environment TZ=EST5EDT,
then TZ=CST6CDT, then TZ=MST7MDT, and finally TZ=PST8PDT./env -n 4 TEMP=EST5EDT,CST6CDT,MST7MDT,PST8PDT 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