Processes in Operating Systems
32 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What happens to a child process when its parent exits in UNIX systems?

  • It is terminated immediately.
  • It becomes an orphan process. (correct)
  • It becomes a zombie process.
  • It continues running without a parent.
  • Which system call is used to create a new process in Linux?

  • create()
  • init()
  • spawn()
  • fork() (correct)
  • What can cause a child process to be terminated?

  • The child process needs to adopt a new parent.
  • The child process exceeds resource usage. (correct)
  • The child process is inactive for a long duration.
  • The parent process finishes execution normally.
  • What is a zombie process?

    <p>A child process that has terminated but not read by the parent.</p> Signup and view all the answers

    How does the resource allocation strategy differ when creating a child process?

    <p>The child duplicates everything from the parent or loads a new set of code.</p> Signup and view all the answers

    What is the return value of fork() for the child process when created successfully?

    <p>0</p> Signup and view all the answers

    What indicates that process creation through fork() has failed?

    <p>The fork() returns a negative value.</p> Signup and view all the answers

    During execution of created processes, what relationship do parent and child processes maintain?

    <p>Parent-child dependency.</p> Signup and view all the answers

    What is the purpose of the wait() system call?

    <p>To check the exit status of the child process.</p> Signup and view all the answers

    Which function is used to load a new program in a child/parent process?

    <p>exec()</p> Signup and view all the answers

    What is the role of IPC (Interprocess Communication) in an operating system?

    <p>To provide communication between different processes.</p> Signup and view all the answers

    What is shared memory in the context of processes?

    <p>A memory region accessible to multiple processes.</p> Signup and view all the answers

    What are the two basic functions required for message passing?

    <p>send(mesg,opt), receive(mesg,opt)</p> Signup and view all the answers

    What is required to implement shared memory in Linux using C?

    <p>Two separate programs, one for sending and one for receiving.</p> Signup and view all the answers

    How is shared memory identified when created?

    <p>By a key with an integer value.</p> Signup and view all the answers

    What does the shmget function return upon successful creation of shared memory?

    <p>A positive value if successful.</p> Signup and view all the answers

    What is the definition of a process in an operating system?

    <p>A program under execution</p> Signup and view all the answers

    Which of the following correctly describes the role of the stack pointer (SP) in a process?

    <p>It points to the top of the stack</p> Signup and view all the answers

    What is the state of a process that is created but not yet ready to execute?

    <p>New</p> Signup and view all the answers

    Which condition describes a process in the 'Waiting' state?

    <p>It is not executing as it waits for a resource or event</p> Signup and view all the answers

    In the context of process states, what is a key difference between the 'Ready' and 'Waiting' states?

    <p>Ready state means resource allocation is complete, while waiting state signifies resource unavailability.</p> Signup and view all the answers

    What information is stored in the Process Control Block (PCB)?

    <p>Details about individual processes including the program counter</p> Signup and view all the answers

    In a 5-state model of process management, which state follows 'Running'?

    <p>Waiting</p> Signup and view all the answers

    What is the purpose of the program counter (PC) in a process?

    <p>To keep track of the next instruction to execute</p> Signup and view all the answers

    What does the IPC_CREAT flag do when used in the shmget function?

    <p>It creates a new shared memory segment if it does not exist.</p> Signup and view all the answers

    What is the purpose of the shmdt function?

    <p>To detach the process from the shared memory.</p> Signup and view all the answers

    Why is it safe to pass a zero as the second argument in the shmat function?

    <p>It allows the OS to find an available memory space.</p> Signup and view all the answers

    What does the function shmctl with IPC_RMID do?

    <p>Deletes the specified shared memory segment.</p> Signup and view all the answers

    Which of the following is a characteristic of multiple threads in modern OS?

    <p>They improve program responsiveness and resource sharing.</p> Signup and view all the answers

    What is one drawback of the One to One thread model?

    <p>It can introduce delays at the kernel level.</p> Signup and view all the answers

    Which thread model is preferred when a limited number of kernel threads are needed?

    <p>Many to Many model.</p> Signup and view all the answers

    Why are threads considered more economical than multiple processes?

    <p>Threads require less CPU time to manage.</p> 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)
    • 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)
    • 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)

    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.

    Quiz Team

    Related Documents

    process.pdf

    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.

    More Like This

    Use Quizgecko on...
    Browser
    Browser