1. For each question, write a short, accurate answer in the space provided. 1) W
ID: 3829453 • Letter: 1
Question
1. For each question, write a short, accurate answer in the space provided.
1) What is segmentation violation? Give a short segment of C codes which has the
segmentation fault.
2) What is an orphan process? Which process adopts the orphan process?
3) What is a critical section? What is an atomic operation?
4) A program generates multiple threads to run different functions respectively at the same
time. What will happen for other threads if we do the following in one of the thread
functions?
(i) Replace the pthread_exit() by exit().
(ii) Add the execlp function.
2. Given the following piece of code:
int main()
{
printf(“my pid is %d ”, getpid() );
fork();
printf(“my pid is %d ”, getpid() );
fork();
printf(“my pid is %d ”, getpid() );
}
How many processes (include the original process) started by this program? How many lines of
total output? How many different lines in the total output?
3 What is the difference between two socket types: SOCK_STREAM and SOCK_DGRAM?
4. We know that video games and operating systems have a lot in common. Using a video game
signal(SIGINT, ouch);
signal(SIGQUIT, ouch);
while(1) {
printf("Hello World! ");
sleep(1);
}
}
1) What is the output of just running the program?
2) What will happen if you try to use both keyboard signals of terminal interrupt and
terminal quit: Ctrl-C and Ctrl- to kill the process?
3) Give exactly necessary commends which can just terminate this process from shell.
Explanation / Answer
1)segmentation violation:
a segmentation fault (often shortened to segfault) or access violation is a fault, or failure condition, raised by hardware with memory protection, notifying an operating system (OS) the software has attempted to access a restricted area of memory (a memory access violation).
->A segmentation violation usually indicates an attempt to access memory which doesn't even exist.
Segmentation violation usually occurs at the time of a program’s attempt for accessing memory location, which is not allowed to access. The following code should create segmentation violation.
main() {
char *hello = “Hello World”;
*hello = ‘h’;
}
At the time of compiling the program, the string “hello world” is placed in the binary mark of the program which is read-only marked. When loading, the compiler places the string along with other constants in the read-only segment of the memory. While executing a variable *hello is set to point the character ‘h’ , is attempted to write the character ‘h’ into the memory, which cause the segmentation violation. And, compiler does not check for assigning read only locations at compile time.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.