Process (1)
Process (1)
● Maximize CPU use, quickly switch processes onto CPU for time
sharing
● Process scheduler selects among available processes for next
execution on CPU
● Maintains scheduling queues of processes
● Job queue – set of all processes in the system
● Ready queue – set of all processes residing in main
memory, ready and waiting to execute
● Device queues – set of processes waiting for an I/O device
● Processes migrate among the various queues
● Long-term scheduler strives for good process mix meaning that it selects a
balanced combination of CPU-bound and I/O-bound processes to ensure
efficient
Operating system
System Concepts
th
– 9 performance 3. Silberschatz, Galvin and Gagne
Schedulers
The short-term scheduler (CPU scheduler) is sometimes the only scheduler in
a system because of the simplicity of process handling in specific types of
systems. This occurs in systems where there is no need for medium-term or
long-term scheduling.
For example:
● In traditional batch systems, jobs are submitted and processed one after
another.
● There is no need for interactive user scheduling, so long-term and
medium-term schedulers are unnecessary.
● The short-term scheduler simply picks the next job when the CPU becomes
idle.
● Execution options
● Parent and children execute concurrently
● Parent waits until children terminate
<sys/types.h>: Defines data types like pid_t (used for process IDs)
<stdio.h>: Includes standard I/O functions (e.g., printf, fprintf)
<unistd.h>: Provides access to POSIX operating system API (e.g., fork, exec, wait)
fork() creates a child process that is an exact copy of the parent process.
pid stores the return value:
If fork() returns a negative value, it indicates a failure (e.g., system resources exhausted)
fprintf(stderr, "Fork Failed"); prints an error message
The child process replaces its memory image with the /bin/ls command using execlp()
execlp() executes the ls command (listing files in the current directory)
If execlp() succeeds, it never returns (as the process image is replaced)
● The parent process waits for the child process to finish using wait(NULL)
● The child process executes ls, displaying the list of files in the current directory.
● Once ls finishes, the parent prints: Child Complete
If a parent process calls wait(), it collects the exit status of the child
and prevents it from becoming a zombie.
The child process terminates immediately. The parent sleeps for 10 seconds, so
it does not collect the child’s exit status. During this time, the child remains a
zombie in the system.