Lab 3 - Processes
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 settingstruct 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 labint setenv(const char* name, const char* value,
int overwrite)
char *getenv(const char *name)
,
%notation
in a string