preview

Nt1310 Unit 1 Question Paper

Decent Essays

Assignment 3 Name: Narendra Kumar Reddy Mule 700#:700622719 3.1 Using the program shown in Figure 3.30 explain what the output will be at Line A. #include #include #include int value = 5; int main() { pid t pid; pid = fork(); if (pid == 0) { /* child process */ value += 15; return 0; } else if (pid > 0) { /* parent process */ wait(NULL); printf("PARENT: value = %d",value); /* LINE A */ return 0; } } Ans: The output at LINE will be …show more content…

How do they differ from those used when a process is created? Ans: As thread is a shared one and it doesn’t store the data instead it shares the data. so Thread uses smaller resources than the process. A context should be created, that includes a register set storage location for Storage at the time of context switching, and a local stack for recording all the procedure call arguments, return values, return addresses, and thread-local storage. Creating a process results in the memory that is being allocated for instructions of program and data, as well as thread-like storage. Code may also be loaded into the allocated memory. 4.11: Is it possible to have concurrency but not parallelism? Explain. Ans: Concurrency is a condition that comes into existence when there is a minimum of two threads are making progress. A more summed up form of Parallelism that can include time-slicing as a form of virtual parallelism.'' In contrast, the parallelism is a condition that comes when at least two threads are executing at the same time''. It is possible for two threads to make progress, though not at the same …show more content…

For each of the following scenarios, describe which is a better locking mechanism-a spinlock or a mutex lock where waiting processes sleep while waiting for the lock to become available. When a thread tries to lock a mutex and it does not succeed, because the mutex is already locked, it will go to sleep, immediately allowing another tread to run. It will continue to sleep until being woken up, which will be the case once the mutex is being unlocked by whatever thread was holding the lock before. When a thread tries to lock a spinlock and it does not succeed, it will continuously re-try locking it, until it finally succeeds: thus it will not allow another thread to take its place. ->The lock is to be held for a short duration. Spinlock ->The lock is to be held for a long duration. Mutex lock ->A thread may be put to sleep while holding the lock Mutex lock 6.2: Explain the difference between preemptive and non-preemptive scheduling. Ans: -> Preemptive scheduling: It allows a process to be interrupting in the middle of Its execution, and takes the CPU away and allocate it to another

Get Access