Question: Could someone please help me solve these problems and try to explain the solution to me? Thanks. 1 Short questions: 3 marks each 1. Let
Could someone please help me solve these problems and try to explain the solution to me? Thanks.
1 Short questions: 3 marks each 1. Let a process P create a child process P1 and a process P create a child process P2. Assuming P and P have died while both P1 and P2 are still alive, what will be the ppids of P1 and P2 Your answer : ppid(P1)= ppid(P2)= 2. It is possible for a process to ignore all incoming signals. Your answer(True/False) : 3. When the system call exit() fails, it returns -1? Your answer(True/False) : 4. A process has the option to change its own PPID. Your answer (True/False) : 5. What happens to a process that receives the SIGKILL signal from the user root? Your answer : 6. A shell script must be compiled before it becomes executable. Your answer(True/False) : 7. If a process is a zombie, then its parent is still alive? Your answer(True/False) : 8. The system call read(0, buff, 100) reads a 100 bytes from the keyboard into array buff. Your answer(True/False) : 9. A process with children will not be blocked by the system call wait(). Your answer(True/False) : 10. What will be printed by the statement below, assuming fd is a valid file descriptor: printf("%d ", lseek(fd, 1000L, SEEK_SET)); Your answer : 2 Tracing: 7 marks each 1. How many "Hi"s will this program print? main(){ for(int i=0; i < 5; i++) fork(); printf("Hi "); } 1 Your answer : 2. How many "Hi"s will this program print? main(){ fork(); for(int i=0; i < 3; i++){ if(!fork()) printf("Hi "); } } Your answer : 3. What will appear on the screen when the following program runs? int main(int argc, char *argv[]){ printf("Hello "); fork(); printf("Windsor"); pause(); printf("Bye "); exit(0); } Your answer : 4. In a few words, what does the bash script below, mySc, when we type mySc 10000. for name in ls *.exe if [[ cat $name | wc -c > $1]]; then rm $name fi done Your answer : 2 5. What will be printed by the program below? int main(void){ int pid; pid=fork(); alarm(3); if(!pid){ sleep(2); printf("Saturday "); }else printf("Today "); sleep(1); printf("Tomorrow "); exit(0); } Your answer : 6. What will appear on the screen: main(){ int n, status; if(fork()) n=100; else n=200; wait(&status); printf("%d ", n); exit(0); } Your answer : 3 7. Given the bash script below, called mySc, explain briefly what happens if we type mySc 1.txt Hello Bonjour 2.txt. num=more $1 | wc -l i=1 while [[ $i -le $num ]]; do for www in head -$i $1 | tail -1; do if [[ $www == $2 ]]; then www=$3 fi echo -n "$www " >> $4 done echo >> $4 let "i = $i + 1" done Your answer : 8. What will be printed by the following program? int main(int argc, char *argv[]){ int n, m=0, fd, i; char data[100][100]; fd=open(argv[1], O_CREAT|O_WRONLY|O_TRUNC); for(i=0; i< 10; i++) write(fd, data[i], 100); n=lseek(fd, m, SEEK_CUR); printf("Value= %d ", n); } Your answer : Value= 4 Coding Using Unix system calls read(), write() and lseek(), write a C program that takes one argument, the name of a file, to duplicate its contents, so that its original contents will be duplicated. For example, if the file contains the followings: Hello my name is BigFoot How are you doing? Bye Bye Then, after processing, the file becomes: Hello my name is BigFoot How are you doing? Bye Bye Hello my name is BigFoot How are you doing? Bye Bye Note that you should use the same file, to be opened for Read/Write. Hint: when you request a read and write opening, use the flag O_RDWR. 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
