Skip to main content

Confused OS Concepts

Difference between MultiProcessor and Multicore Processor?mulit core
multiprocessor system contains more than one CPU, allowing them to work in parallel.
multicore CPU has multiple execution cores on one CPU so that multiple cores can work in parallel on separate operations at chip level.
Difference between MultiProgramming, MultiTasking, MultiProcessing,      MultiThreading?
MultiProgramming:To minimize the CPU Idle time, Multiprogramming was introduced in older days for single core processor. One or more programs are loaded into main memory which are ready to execute still, only one program is able to get the CPU for execution while all others are waiting for their turn. When currently running process is performing an I/O task, then OS may interrupt that process and give the control to another program(process context switching) loaded in main memory for execution and a running process keeps executing until either it voluntarily releases the CPU or when it blocks for an I/O operation.
With MutilProgramming, OS should perform decision making as multiple jobs now needed to be loaded into memory at the same time and several options existed for allocating CPU time.
To handle Decision making two types of scheduling were introduced
Job Scheduling –  refers to the selection of jobs to load into memory.
CPU scheduling – refers to the selection of a job existing in memory to execute via the CPU.
Another issue that needs to be handled as well is that large programs may not fit at once in memory which was solved by using pagination and virtual memory.
MultiTasking:Multitasking has the same meaning of multiprogramming but in a more general sense, it is the concurrent execution of multiple tasks (processes) over a certain period of time. New tasks can interrupt already started ones before they finish, instead of waiting for them to end. As a result, a computer executes segments of multiple tasks in an interleaved manner, while the tasks share common processing resources such as CPU and main memory.
The concept of multitasking is that the CPU time is shared equally among the processes or tasks. In multiprogramming (older OS) one program as a whole keeps running until it blocks or ends, in multitasking (modern OS) time-sharing is best manifested because each running process takes only a fair quantum of the CPU time.
For example, Consider that 3 tasks are loaded into the main memory and time allocated for each program is 3 microseconds. Now the first task executing, after 3 microseconds irrespective whether the task gets completed or not it gets switched to the second task. Similarly, after 3 microseconds it goes to the third task. Thus the CPU time is shared equally among the tasks.
Multitasking takes place in a single processor or sometimes multiprocessor and multitasking does not require parallel execution of multiple tasks at exactly the same time instead, it allows more than one task to advance over a given period of time. Even on multiprocessor computers, multitasking allows many more tasks to be run than there are CPUs.
MultiThreadingMultithreading is thread-based multitasking.
The basic difference between multitasking and multithreading is that in multitasking, the system allows executing multiple programs and tasks at the same time, whereas, in multithreading, the system executes multiple threads of the same or different processes at the same time.
In multitasking, CPU has to switch between multiple programs so that it appears that multiple programs are running simultaneously. On other hands, in multithreading CPU has to switch between multiple threads to make it appear that all threads are running simultaneously.
Multitasking allocates separate memory and resources for each process/program whereas, in multithreading threads belonging to the same process shares the same memory and resources as that of the process.
Multiprocessing refers to the hardware (i.e., the CPU units) rather than the software (i.e., running processes). If the underlying hardware provides more than one processor then that is multiprocessing.
Multiprocessing is the use of two or more CPUs (processors) within a single Computer system. The term also refers to the ability of a system to support more than one processor within a single computer system. Now since there are multiple processors available, multiple processes can be executed at a time. These multiprocessors share the computer bus, sometimes the clock, memory and peripheral devices also.
Multiprocessing system’s working –
  • With the help of multiprocessing, many processes can be executed simultaneously. Say processes P1, P2, P3, and P4 are waiting for execution. Now in a single processor system, firstly one process will execute, then the other, then the other and so on.
  • But with multiprocessing, each process can be assigned to a different processor for its execution. If its a dual-core processor (2 processors), two processes can be executed simultaneously and thus will be two times faster, similarly a quad-core processor will be four times as fast as a single processor.
Why use multiprocessing –
  • The main advantage of a multiprocessor system is to get more work done in a shorter period of time. These types of systems are used when very high speed is required to process a large volume of data. Multiprocessing systems can save money in comparison to single processor systems because the processors can share peripherals and power supplies.
  • It also provides increased reliability in the sense that if one processor fails, the work does not halt, it only slows down. e.g. if we have 10 processors and 1 fails, then the work does not halt, rather the remaining 9 processors can share the work of the 10th processor. Thus the whole system runs only 10 percent slower, rather than failing altogether.

Difference between Synchronous and Asynchronous programming.
Synchronous ProgrammingProgram execution in most high-level languages is usually very straightforward. Your program starts at the first line of source code and each line of code executed sequentially thereafter.  Synchronous program execution is somewhat similar to the above. Your program is executed line by line, one line at a time. Each time a function is called, program execution waits until that function returns before continuing to the next line of code.
Suppose a function is called to start a time-consuming process, the whole application has to wait until it finishes, this is a disadvantage of synchronous programming.
Asynchronous Programming is a form of parallel programming that allows a unit of work to run separately from the primary application thread. When the work is complete, it notifies the main thread (as well as whether the work was completed or failed). There are numerous benefits to using it, such as improved application performance and enhanced responsiveness.
Suppose a time-consuming process is called, the application doesn’t wait for this to complete and continue executing next instructions sequentially, this process notifies the application thread or main thread after it completes.


Popular posts from this blog

UILabel text animation as in UIButton click

Animating UILabel textcolor is not easy as it seems, normal animation won't work on this property. The below code snippet animates the UILabel textcolor as in button click. Change the duration and UIViewAnimationOptions to play with it. extension UILabel { func flashLabel() { func animate(duration: Double ,alpha: CGFloat ,completion:(()->())?){ UIView . transition (with: self , duration: duration, options: UIViewAnimationOptions . transitionCrossDissolve , animations: { self . textColor = self . textColor ?. withAlphaComponent (alpha) }) { _ in completion?() } } animate (duration: 0.1 , alpha: 0 ) { animate (duration: 0.3 , alpha: 1 , completion: nil ) } } } Happy coding...

Design Patterns in Swift

What is a Design pattern? A design pattern is a general solution to a real-world problem that can be re-used. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. They are templates designed to help us write efficient code which is easy to understand, also can be re-used. It is not a finished design that can be transformed directly into source or machine code. Why do we need Design patterns? Saves Time : Design patterns can speed up the development process by providing tested, proven development paradigms Future bugs : Effective design pattern can solve issues that may not become visible until later in the implementation, which helps while designing software. Re-use : Reusing design patterns helps to prevent subtle issues that can cause major problems. Code Readability : Improves code readability for coders and architects familiar with the patterns. Best practices : Design patterns teaches