Open In App

Python | os.wait() method

Last Updated : 26 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.wait() method in Python is used by a process to wait for completion of a child process.
This method returns a tuple containing its PID and exit status indication. The exit status of child process is indicated by a 16 bit number whose lower byte is the signal number that killed the process and higher byte is the exit status (if the signal number is zero).

Syntax: os.wait()

Parameter: No parameter is required.

Return type: This method returns a tuple which contains terminated child’s PID and exit status indication.

Code: Use of os.wait() method




# Python program to explain os.wait() method 
  
# importing os module  
import os 
  
# Create a child process
# using os.fork() method 
pid = os.fork()
  
  
# a Non-zero process id (pid)
# indicates the parent process 
if pid :
      
    # Wait for the completion of
    # child process using
    # os.wait() method    
    status = os.wait()
    print("\nIn parent process-")
    print("Terminated child's process id:", status[0])
    print("Signal number that killed the child process:", status[1])
  
else :
    print("In Child process-")
    print("Process ID:", os.getpid())
    print("Hello ! Geeks")
    print("Exiting")
      
  
# using os.wait() method    
# Parent process will wait till 
# the completion of child process
# and then only it will 
# begin its execution


Output:

In Child process-
Process ID: 6276
Hello! Geeks
Exiting

In parent process-
Terminated child's process id: 6276
Signal number that killed the child process: 0

Previous Article
Next Article

Similar Reads

Selenium Wait Commands - Implicit, Explicit, and Fluent Wait
Selenium Python is one of the great tools for testing automation. These days most web apps are using AJAX techniques. When a page is loaded by the browser, the elements within that page may load at different time intervals. This makes locating elements difficult: if an element is not yet present in the DOM, a locate function will raise an ElementNo
5 min read
Python - Stop & Wait Implementation using CRC
Stop and wait protocol is an error control protocol, in this protocol the sender sends data packets one at a time and waits for positive acknowledgment from the receiver's side, if acknowledgment is received then the sender sends the next data packet else it'll resend the previous packet until a positive acknowledgment is not received. Note: To get
7 min read
Make Python Wait For a Pressed Key
Halting the execution until the occurrence of an event is a very common requirement in prompt-based programs. In earlier times, the presence of functions such as getch in C/C++ was almost necessary for the code to make the console stay up to display the output. Now such shortcomings of the compiler have been dealt with, and now such functions serve
3 min read
How to make a Python program wait?
Have you ever encountered a scenario where you wanted your Python application to pause or run for a predetermined amount of time? You're not by yourself. Python can pause its execution with the wait function, much like a well-timed comic, yet many coders find themselves in need of this feature. We'll take you step-by-step through the Python wait fu
5 min read
Class Method vs Static Method vs Instance Method in Python
Three important types of methods in Python are class methods, static methods, and instance methods. Each serves a distinct purpose and contributes to the overall flexibility and functionality of object-oriented programming in Python. In this article, we will see the difference between class method, static method, and instance method with the help o
5 min read
Class method vs Static method in Python
In this article, we will cover the basic difference between the class method vs Static method in Python and when to use the class method and static method in python. What is Class Method in Python? The @classmethod decorator is a built-in function decorator that is an expression that gets evaluated after your function is defined. The result of that
4 min read
Difference between Method Overloading and Method Overriding in Python
Method Overloading: Method Overloading is an example of Compile time polymorphism. In this, more than one method of the same class shares the same method name having different signatures. Method overloading is used to add more to the behavior of methods and there is no need of more than one class for method overloading.Note: Python does not support
3 min read
Pandas DataFrame iterrows() Method | Pandas Method
Pandas DataFrame iterrows() iterates over a Pandas DataFrame rows in the form of (index, series) pair. This function iterates over the data frame column, it will return a tuple with the column name and content in the form of a series. Example: Python Code import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 32, 3
2 min read
Pandas DataFrame interpolate() Method | Pandas Method
Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.  Python Pandas interpolate() method is used to fill NaN values in the DataFrame or Series using various interpolation techniques to fill the m
3 min read
Pandas DataFrame duplicated() Method | Pandas Method
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas duplicated() method identifies duplicated rows in a DataFrame. It returns a boolean series which is True only for unique rows. Ex
3 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg