Inter Process Communication Basics
45 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 information does the ps command provide?

  • List of open files of running processes
  • Statistics of virtual memory subsystem
  • System configuration variables
  • Information about all running processes (correct)

Which command reports on virtual memory statistics?

  • ps
  • lsof
  • vmstat (correct)
  • getconf

What does the getrusage() system call provide information about?

  • System resource usage (correct)
  • Number of running processes
  • System configuration variables
  • Open files of a process

Which command would you use to display system configuration variables?

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

What does a successful call to getrusage() return?

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

What is the process image primarily used for?

<p>Preparing the executable file for program execution (B)</p> Signup and view all the answers

Which segment of the process image is read-only and contains executable instructions?

<p>Code segment (D)</p> Signup and view all the answers

How does the stack segment manage memory?

<p>In a Last-In-First-Out (LIFO) order (B)</p> Signup and view all the answers

What does the child process return in the provided program found in the main function?

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

Which type of data segment contains uninitialized static and global variables?

<p>BSS segment (C)</p> Signup and view all the answers

In the program, which function is used to wait for the child process to finish executing?

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

What function calls are typically associated with the heap segment?

<p>malloc() and calloc() (B)</p> Signup and view all the answers

What is characteristic of the data segment's size during program execution?

<p>It can change due to variable modifications. (D)</p> Signup and view all the answers

What happens if the waitid function encounters an error during execution?

<p>Returns -1 and sets appropriate error number (A)</p> Signup and view all the answers

What is the purpose of a process group in Unix-like operating systems?

<p>To group multiple processes sharing the same PGID (A)</p> Signup and view all the answers

In which order does the stack segment grow?

<p>From higher address to lower address (B)</p> Signup and view all the answers

What command can be executed to determine segment size?

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

What is the role of the process group leader?

<p>To create the process group and own the PGID (A)</p> Signup and view all the answers

Which statement best describes sessions in process management?

<p>It is a collection of process groups (C)</p> Signup and view all the answers

What enables a shell user to manage multiple commands simultaneously?

<p>Job Control (D)</p> Signup and view all the answers

In the context of the program, what is indicated by the return value of 1 for the main function?

<p>Error occurred during waitid execution (D)</p> Signup and view all the answers

What is the purpose of the chmod command in the context of shell scripts?

<p>To provide execute permissions to the file (C)</p> Signup and view all the answers

Which command is used to resume a stopped job in the foreground?

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

What is a process ID (PID)?

<p>A unique positive integer identifying a process (C)</p> Signup and view all the answers

What command would you use to list jobs currently managed by the shell?

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

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

<p>To return the process ID of the calling process (A)</p> Signup and view all the answers

Which command displays the ongoing CPU and memory resource usage in real-time?

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

What is the maximum limit for process IDs in the system?

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

Which system call is used to get the parent process ID?

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

To stop a currently running process in the shell, which key combination should you use?

<p>CTRL+Z (B)</p> Signup and view all the answers

What function does the system() library function serve in the provided program?

<p>To execute a shell command (C)</p> Signup and view all the answers

What happens when you use the kill command with a specific job number?

<p>It terminates the specified job (B)</p> Signup and view all the answers

In shell scripting, what does the sleep command do?

<p>It pauses execution for a specified duration (C)</p> Signup and view all the answers

What will the command 'ps -ef' provide when called in the program?

<p>Details of the current active processes (D)</p> Signup and view all the answers

What does the output 'My process ID is %d' signify in the program?

<p>The unique identifier of the calling process outputted as an integer (D)</p> Signup and view all the answers

What will happen if you attempt to run a job in the background using the command bg %2?

<p>It starts the second stopped job in the background (A)</p> Signup and view all the answers

Which of the following best describes the return value of the getppid() call?

<p>It always returns a unique identifier of the parent process (B)</p> Signup and view all the answers

What is the output produced by the command getppid() in the child process?

<p>PPID is 166629 (C)</p> Signup and view all the answers

What happens when the fork() function returns a negative value?

<p>An error occurs indicating fork() failure. (A)</p> Signup and view all the answers

Which of the following correctly describes the difference between exit() and _exit()?

<p>exit() performs cleanup before control returns to the kernel, while _exit() does not. (A)</p> Signup and view all the answers

What function is used to register a cleanup function that is called upon normal termination of a program?

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

In the sample program with 'atexit_sample.c', what is printed just before the program exits?

<p>Hello, World! (B)</p> Signup and view all the answers

Which option correctly states the output when both the parent and child processes execute after a fork() call?

<p>The parent process will have a different PID from the child process. (B)</p> Signup and view all the answers

What is the behavior of the program if the function registered by atexit() is not called?

<p>The program may not clean up resources properly. (A)</p> Signup and view all the answers

What will happen if the program with atexit_sample.c registers multiple functions with atexit()?

<p>Functions will be called in reverse order of registration. (D)</p> Signup and view all the answers

Flashcards

What does the 'ps' command do?

The ps command displays information about all running processes, helping you monitor and manage them.

What is the purpose of the 'vmstat' command?

Displays statistics about the virtual memory system, including process status, memory usage, swap space, I/O activity, and CPU time.

How does the 'lsof' command work?

The lsof command lists the open files used by all running processes, including system processes.

What is the purpose of the 'getconf' command?

The getconf command is used to view system configuration settings, providing information about the operating system environment.

Signup and view all the flashcards

What does the 'getrusage()' function do?

The getrusage() system call retrieves information on the resource usage by a process, including its children and threads.

Signup and view all the flashcards

Program

A file containing instructions for a process, loaded into RAM during execution.

Signup and view all the flashcards

Process ID (PID)

A unique positive integer assigned to each running process, identifying it.

Signup and view all the flashcards

Process ID Limit

The maximum value a process ID can reach, usually set to 32767, but configurable.

Signup and view all the flashcards

Parent Process

The process that created another process, also known as the child process.

Signup and view all the flashcards

getpid()

A system call that returns the Process ID (PID) of the calling process.

Signup and view all the flashcards

Parent Process ID (PPID)

A unique identifier for a process indicating its parent.

Signup and view all the flashcards

getppid()

A system call used to retrieve the Parent Process ID (PPID) of the calling process.

Signup and view all the flashcards

system()

A C library function that executes a shell command, allowing you to run programs or scripts within your code.

Signup and view all the flashcards

What is the purpose of the 'date' command?

Allows execution of commands on a Linux or Unix system like displaying the current date and time.

Signup and view all the flashcards

What does the 'sleep' command do?

Pauses the execution of a shell script for a specified duration in seconds.

Signup and view all the flashcards

How does the 'cal' command work?

Displays a calendar for the current month.

Signup and view all the flashcards

Explain the functionality of the basic_commands.sh script.

A combination of commands for displaying the date, pausing execution for 10 seconds, and then showing a calendar.

Signup and view all the flashcards

Describe the process_status.sh script.

A shell script combining the 'ps' command to list processes, a 20-second sleep, and another 'ps' command.

Signup and view all the flashcards

What are process resources?

A process needs resources like CPU and memory. Monitoring commands help understand resource utilization and set limits for processes.

Signup and view all the flashcards

What is the 'top' command?

A command that shows real-time resource usage of processes. It helps identify resource-intensive processes.

Signup and view all the flashcards

fork()

A function that creates a new process, which is a copy of the calling process. It returns the process ID (PID) of the newly created process to the parent process, and 0 to the child process. If an error occurs, it returns -1.

Signup and view all the flashcards

Child process

The newly created process that is a copy of the parent process.

Signup and view all the flashcards

waitid()

A function in the C library used to wait for a child process to finish execution.

Signup and view all the flashcards

siginfo_t

A data structure that contains information about a process, including its PID, user ID, and exit status.

Signup and view all the flashcards

Process Group

A group of processes that share the same process group ID (PGID).

Signup and view all the flashcards

Sessions

A collection of various process groups.

Signup and view all the flashcards

Code Segment

A collection of executable instructions in a program's virtual address space.

Signup and view all the flashcards

Initialized Data Segment

A section of a program's virtual address space that stores initialized static and global variables.

Signup and view all the flashcards

Un-initialized Data Segment (BSS)

A section of a program's virtual address space that stores uninitialized static and global variables.

Signup and view all the flashcards

Stack Segment

An area of memory used to store automatic variables, function parameters, and return addresses for function calls.

Signup and view all the flashcards

Heap Segment

An area of memory used for dynamic memory allocation using functions like malloc() and calloc() to store data.

Signup and view all the flashcards

Process Image

A complete representation of a program in memory, containing code, data, and stack information needed for execution.

Signup and view all the flashcards

Proc File System

The process of obtaining information about running processes and the system.

Signup and view all the flashcards

Size Command

The command used to determine the size of various segments in a program's memory.

Signup and view all the flashcards

atexit() function

A function that is triggered when a program terminates normally. It can be used to execute cleanup tasks before the program ends.

Signup and view all the flashcards

Terminate signal

A special kind of signal that tells a process to terminate immediately.

Signup and view all the flashcards

exit() function

A function that terminates the current process and returns an exit status to the parent process.

Signup and view all the flashcards

Parent Process (PPID)

Represents the process that created the current process. It's like your family line.

Signup and view all the flashcards

Study Notes

Inter Process Communication (IPC)

  • IPC is a mechanism for communication between processes in a single system.
  • Two types of processes can communicate: related processes and unrelated processes.
  • Related processes initiate communication from one to another (e.g., parent and child).
  • Unrelated processes can communicate with each other.

Pipes

  • Used for communication between related processes.
  • Half-duplex communication is possible; one process communicating to another.
  • To achieve full-duplex communication (both ways), two pipes are required.

FIFO

  • Used for communication between unrelated processes.
  • Enables full-duplex communication (both ways simultaneously).

Message Queues

  • Enables communication between two or more processes.
  • Full-duplex communication is possible.
  • Processes communicate through posting and retrieving messages from a queue.
  • Messages are removed from the queue after being retrieved.

Shared Memory

  • Used for communication between two or more processes via a common memory area.
  • Synchronization mechanisms to protect the shared memory from concurrent access are needed.

Semaphores

  • Synchronization mechanisms used to coordinate access to shared memory by multiple processes.
  • A semaphore acts as a lock or protection mechanism to prevent multiple processes from accessing the shared memory simultaneously.
  • A process that wants to access shared memory must lock the semaphore.
  • The semaphore is released when the access is no longer needed.

Signals

  • A mechanism for communication between multiple processes.
  • One process sends a signal, and the destination process handles it.
  • Signals are identified by a number and recognized by the process.

Process Information

  • A process is a program in execution.
  • A program is a file containing instructions for a process.
  • Each process has a unique positive integer called a process ID (PID).
  • The kernel sets limits on the maximum PID value.
  • The system call getpid() returns the PID of the calling process.
  • The system call getppid() returns the parent process ID (PPID).

Process Image

  • Contains the executable instructions: code segment or text segment.
  • Data segment: static & global variables, initialized & uninitialized (BSS).
  • Stack segment: Automatic variables & function parameters usage (LIFO).
  • Heap segment: Dynamically allocated variables (growing downward from high addresses).

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

This quiz covers the essential mechanisms of Inter Process Communication (IPC), including pipes, FIFO, message queues, and shared memory. You'll learn about how processes, both related and unrelated, communicate using these different methods. Test your understanding of these concepts and their applications in computer systems.

More Like This

Use Quizgecko on...
Browser
Browser