Understanding Operating System Processes and Scheduling
OS Processes: An Introduction
OS and Processes:
On a single-user system such as Microsoft Windows, a user may be able to run several programs at one time: a word processor, a web browser, and an e-mail package. Even if the user can execute only one program at a time, the operating system may need to support its own internal programmed activities, such as memory management. In many respects, all these activities are similar, so we call all of them processes.
What is a Process?
A process is a program in execution. A process is more than the program code, which is sometimes known as the text section. It also includes the current activity, as represented by the value of the program counter and the contents of the processor’s registers.
A process generally also includes the process stack, which contains temporary data (such as function parameters, return addresses, and local variables), and a data section, which contains global variables. A process may also include a heap, which is memory that is dynamically allocated during process run time.
Understanding pthread_cond_signal
The pthread_cond_signal()
function shall unblock at least one of the threads that are blocked on the specified condition variable cond
(if any threads are blocked on cond
).
If more than one thread is blocked on a condition variable, the scheduling policy shall determine the order in which threads are unblocked. When each thread unblocked as a result of a pthread_cond_broadcast()
or pthread_cond_signal()
returns from its call to pthread_cond_wait()
or pthread_cond_timedwait()
, the thread shall own the mutex with which it called pthread_cond_wait()
or pthread_cond_timedwait()
. The thread(s) that are unblocked shall contend for the mutex according to the scheduling policy (if applicable), and as if each had called pthread_mutex_lock()
.
The pthread_cond_timedwait()
and pthread_cond_wait()
functions shall block on a condition variable. They shall be called with mutex
locked by the calling thread or undefined behavior results.
Non-Preemptive Scheduling
A scheduling discipline is non-preemptive if, once a process has been given the CPU, the CPU cannot be taken away from that process.
Following are some characteristics of non-preemptive scheduling:
- In a non-preemptive system, short jobs are made to wait by longer jobs, but the overall treatment of all processes is fair.
- In a non-preemptive system, response times are more predictable because incoming high-priority jobs cannot displace waiting jobs.
- In non-preemptive scheduling, a scheduler executes jobs in the following two situations:
- When a process switches from the running state to the waiting state.
- When a process terminates.
Preemptive Scheduling
A scheduling discipline is preemptive if, once a process has been given the CPU, it can be taken away.
The strategy of allowing processes that are logically runnable to be temporarily suspended is called Preemptive Scheduling, and it is in contrast to the “run to completion” method.