Posts

Showing posts with the label atomic

Atomic variables in Linux

Image
Consider the following program below, try to guess why the output is not 1,00,000 Code: Output: The reason behind it is giving different values each time is SMP Machine. In a multi processor system, global++ will be converted to global = global + 1. Steps to increment the value of global by 1: 1. Processor reads the value of global 2. Processor increments the value in memory 3. Processor writes the new value to global Let's take the example of global value is 5, and there are two processors in system , Processor 1 and Processor 2. Processor 1 reads the value of global and it is 5. Processor 1 increments the value in memory and make it 6 Processor 2 acquires the bus and reads the value of global and it will be 5 Processor 2 increments the value in memory and make it 6 Processor 1 comes and then writes 6 to global variable Processor 2 comes and then writes 6 to global variable. How to solve this problem? The simultaneous access problem...

os interview questions

OS INTERVIEW QUESTIONS These are some of the basic interview questions asked on operating system 1.      What is the difference between multitasking,multiprocessing,batch processing ,multiuser? 2.      What is the difference between monolithic and micro kernel? 3.      How to create Dynamic and static library? 4.      How to create a process in linux? 5.      Difference between pipes and named pipes? 6.      All POSIX API for  example what are the API of semaphores? 7.      What are the different types of mutex? 8.      What is conditional variables? 9.      What are barriers? 10.                         What are read write locks? 11.      ...