Podcast
Questions and Answers
What happens to a child process when its parent exits in UNIX systems?
What happens to a child process when its parent exits in UNIX systems?
Which system call is used to create a new process in Linux?
Which system call is used to create a new process in Linux?
What can cause a child process to be terminated?
What can cause a child process to be terminated?
What is a zombie process?
What is a zombie process?
Signup and view all the answers
How does the resource allocation strategy differ when creating a child process?
How does the resource allocation strategy differ when creating a child process?
Signup and view all the answers
What is the return value of fork() for the child process when created successfully?
What is the return value of fork() for the child process when created successfully?
Signup and view all the answers
What indicates that process creation through fork() has failed?
What indicates that process creation through fork() has failed?
Signup and view all the answers
During execution of created processes, what relationship do parent and child processes maintain?
During execution of created processes, what relationship do parent and child processes maintain?
Signup and view all the answers
What is the purpose of the wait() system call?
What is the purpose of the wait() system call?
Signup and view all the answers
Which function is used to load a new program in a child/parent process?
Which function is used to load a new program in a child/parent process?
Signup and view all the answers
What is the role of IPC (Interprocess Communication) in an operating system?
What is the role of IPC (Interprocess Communication) in an operating system?
Signup and view all the answers
What is shared memory in the context of processes?
What is shared memory in the context of processes?
Signup and view all the answers
What are the two basic functions required for message passing?
What are the two basic functions required for message passing?
Signup and view all the answers
What is required to implement shared memory in Linux using C?
What is required to implement shared memory in Linux using C?
Signup and view all the answers
How is shared memory identified when created?
How is shared memory identified when created?
Signup and view all the answers
What does the shmget function return upon successful creation of shared memory?
What does the shmget function return upon successful creation of shared memory?
Signup and view all the answers
What is the definition of a process in an operating system?
What is the definition of a process in an operating system?
Signup and view all the answers
Which of the following correctly describes the role of the stack pointer (SP) in a process?
Which of the following correctly describes the role of the stack pointer (SP) in a process?
Signup and view all the answers
What is the state of a process that is created but not yet ready to execute?
What is the state of a process that is created but not yet ready to execute?
Signup and view all the answers
Which condition describes a process in the 'Waiting' state?
Which condition describes a process in the 'Waiting' state?
Signup and view all the answers
In the context of process states, what is a key difference between the 'Ready' and 'Waiting' states?
In the context of process states, what is a key difference between the 'Ready' and 'Waiting' states?
Signup and view all the answers
What information is stored in the Process Control Block (PCB)?
What information is stored in the Process Control Block (PCB)?
Signup and view all the answers
In a 5-state model of process management, which state follows 'Running'?
In a 5-state model of process management, which state follows 'Running'?
Signup and view all the answers
What is the purpose of the program counter (PC) in a process?
What is the purpose of the program counter (PC) in a process?
Signup and view all the answers
What does the IPC_CREAT flag do when used in the shmget function?
What does the IPC_CREAT flag do when used in the shmget function?
Signup and view all the answers
What is the purpose of the shmdt function?
What is the purpose of the shmdt function?
Signup and view all the answers
Why is it safe to pass a zero as the second argument in the shmat function?
Why is it safe to pass a zero as the second argument in the shmat function?
Signup and view all the answers
What does the function shmctl with IPC_RMID do?
What does the function shmctl with IPC_RMID do?
Signup and view all the answers
Which of the following is a characteristic of multiple threads in modern OS?
Which of the following is a characteristic of multiple threads in modern OS?
Signup and view all the answers
What is one drawback of the One to One thread model?
What is one drawback of the One to One thread model?
Signup and view all the answers
Which thread model is preferred when a limited number of kernel threads are needed?
Which thread model is preferred when a limited number of kernel threads are needed?
Signup and view all the answers
Why are threads considered more economical than multiple processes?
Why are threads considered more economical than multiple processes?
Signup and view all the answers
Study Notes
Process
- A process is a program under execution.
- A process can also be referred to as a "job" or a "task".
- A process contains program instructions (code) and data variables.
- The instructions and variables are loaded into memory before execution.
- Machine language is heavily dependent on the processor the process runs on.
Process Components
- Text: The code of the process.
- Data: Data variables present prior to execution.
- Stack: Stores intermediate results, return addresses, etc.
- Heap: Used for allocating variable space during runtime.
Process States
- New: The process is just created.
- Ready: The process has all its resources but is waiting for processor time.
- Running: The process is currently executing.
- Waiting: The process is not running and waiting for a resource or event.
- Stop/Terminated: The process has finished execution.
5-State Process Model
- Each process state has an associated queue.
- Difference between Ready and Waiting states:
- Ready: Process is ready to execute but waiting for processor allocation.
- Waiting: Process is paused, waiting for a resource or event (e.g., I/O completion).
7-State Process Model
- The 7-state model includes Ready-suspend and Blocked-suspend.
- In these states, the process is contending for resources but is suspended.
Process Control Block (PCB)
- The PCB stores details about an individual process.
- Every process has a unique ID or number.
- The program counter points to the next instruction to be executed.
- The PCB may include priority information.
PCB and Process States
- When transitioning between states, the process details are saved in the PCB.
- This information is loaded from the PCB when the process is selected again for execution.
- The PCB is stored in main memory.
- Most operating systems maintain an index of PCBs.
Process Creation
- New processes are created using system calls.
- Resources, including memory, are allocated to the process.
- Processes have a parent-child relationship.
- In UNIX systems, 'init' is the first process.
Process Creation Strategies
- Duplicate: The child process duplicates everything from the parent.
- New Resources: A new set of code and other elements are loaded into the child's address space.
Process Termination
- Normal Termination: The process finishes executing its code.
-
Child Process Termination:
- Child process exceeds resource usage.
- The parent process exits, and the OS doesn't allow the child to continue.
Orphan and Zombie Processes
- Orphan Process: A child process whose parent has exited.
- Zombie Process: A child process that has exited, but its exit status is still in the process table and needs to be read by the parent.
- In UNIX systems, orphaned processes are adopted by the 'init' process.
fork() System Call
- Purpose: Creates a new process in Linux.
- Child Process: Duplicates the parent's memory contents.
-
Execution: Both parent and child continue execution from the instruction following the
fork()
. -
Return Values:
- Negative: Process creation failed.
- Zero: Child process.
- Positive: Parent process.
Using Parent and Child Processes
- The return value of
fork()
distinguishes between parent and child. - wait() System Call: Allows the parent to wait for the child process to terminate and get its exit signal.
Loading a New Program
- The
exec()
family of functions loads a new program into the parent or child process. - Example:
execlp("ls", "ls", NULL);
Loads the 'ls' command to list directory contents.
Interprocess Communication (IPC)
- Each process has its own memory space that other processes cannot access.
-
Reasons for IPC:
- Sharing results from subtasks.
- Sharing common information.
-
IPC Mechanisms:
- Shared Memory: A region in memory accessible to multiple processes.
- Message Passing: Information sharing facilitated by the OS using a kernel space.
Shared Memory
- A region in memory is allocated for processes that want to share data.
- The process initiating the sharing procedure allocates the space.
- Processes need to ensure that their read and write operations do not affect other parts of memory.
Message Passing
- The OS facilitates information sharing through a kernel space.
- Similar to a mailbox.
-
Functions:
- send(mesg,opt): Sends a message.
- receive(mesg,opt): Receives a message.
Implementing Shared Memory in Linux using C
- Requires two separate programs: one for writing messages, another for reading.
- Key: Used to uniquely identify the shared memory.
-
shmget()
: Creates the shared memory.- Arguments:
- Key
- Buffer size
- Creation code (e.g.,
IPC_CREAT
)
- Arguments:
-
Return Values:
- Positive: Success
- Negative: Failure
-
shmat()
: Attaches to the shared memory.- Arguments:
-
shmget()
return id - Address (zero for OS to find free space)
- Flags (set to zero)
-
- Arguments:
-
shmdt()
: Detaches the shared memory. -
shmctl()
: Controls the shared memory.- Arguments:
- Shared memory id
- Control operation (e.g.,
IPC_RMID
for deletion) - Buffer (NULL for deletion)
- Arguments:
Threads
- A thread is a unit of execution or flow of control within a process.
- Modern operating systems support multiple threads.
- Running multiple threads requires hardware support.
- Multithreaded applications need to be designed to prevent conflicts.
Advantages of Multithreading
- Improved program responsiveness: Multiple tasks can execute concurrently.
- Resource sharing: Threads within a process share the same resources.
- Scalability: Can utilize multiple processors effectively.
Thread Models
- One-to-One: Each user-level thread maps to a kernel-level thread.
- One-to-Many: Multiple user-level threads map to one kernel-level thread.
- Many-to-Many: Multiple user-level threads map to a fixed number of kernel-level threads.
Thread Model Considerations
- One-to-One: May cause delays at the kernel level due to thread creation overhead.
- One-to-Many: Not commonly used due to resource intensive kernel thread creation.
- Many-to-Many: Preferable when the number of kernel threads is limited.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz explores the concept of processes in operating systems, including their components, states, and the 5-state process model. Understand how processes function and the significance of each state in execution. Test your knowledge on the fundamental aspects of process management.