You are on page 1of 4
Assignment 2 uestion 1 & 2: #include #include #include int main(int arge, char * argv) { if (arge != 3) { Print{("Invalid arguments\n"); return 0; } int status; pid_t fork_retumn; char * myargvi] = { "Ibiniep", argv(1], argv(2], NULL hk fork_return = fork(); if (fork_return == 0) { printf("in the CHILD process, trying to copy. \n"); printf("The ID of the original process is %d and the parent process is %d \n", getpid(), getppid(); / execl(myargv(0], myargy{1], myargy(2}, myargv[3], myargvi4], myargv{5})); execv(myargy[0], myargy); Jelse if (fork_return > 0) { wait( & status); print{("In the PARENT processin"); printf("The ID of the original process is %d and the parent process is %d \n", getpid(), getppid()); Jelse { printf("Error\n"); ) return 0; } rp Q2 1. No, it won't print because after exec" is called, the calling process is replaced by the process called using exec*, and the control is not transferred back to the calling process. 2. The terminal which is used to run the program is the parent. 3. By removing the wait(8status) line. 4. -p-imean to preserve file's data like owner, timestamps, etc. and interact with the user to replace file if required ” Tra) eRe acco rc) PCRS Cet eee CEE ene etc ee ce eee Question 3: #include #include #include #include int main() { int x; if (fork() == 0) exit(1) else wait( & x); if (WIFEXITED()) printf("Exit status: %d\n", WEXITSTATUS(x)); else if (WIFSIGNALED(x)) psignal(WTERMSIG(x), "Exit signal"); return 0; } es Question 4; #include #include #include int main() { pid_t x = fork(); if (== 0) { execl("/usr/bin/firefox", 0); }else { exeel("/binis", "Is", "I", ".", 0) } return 0;

You might also like