Python os.wifcontinue() - 检查进程是否从作业控制停止继续

Python os.wifcontinue()方法

Python中的os. wifcontinue()方法用于检查进程是否从作业控制停止继续。此方法以os.wait()、os.system()或os.waitpid()方法返回的进程状态码作为参数,如果进程已经停止则返回True,否则返回False。

os.wifcontinue语法

os. wifcontinue (status) 

os.wifcontinue 参数

status:该参数接受进程状态码(一个整数值),由os.system(),os.wait()或os.waitpid()方法返回。

返回类型:该方法返回一个布尔值,类为’bool’。如果进程从作业控制停止处继续,此方法返回True,否则返回False。

os.wifcontinue 示例

os. wifcontinue()方法的使用

# Python program to explain os.WIFCONTINUED() method 
  
# importing os and signal module  
import os, signal
  
# Create a child process
# using os.fork() method 
pid = os.fork()
  
  
# pid greater than 0
# indicates the parent process 
if pid :
      
    # Send signal 'SIGSTOP'
    # to child process
    # using os.kill() method
    # signal 'SIGCONT' will cause
    # the child process to stop
    os.kill(pid, signal.SIGSTOP)
  
    # Send signal 'SIGCONT'
    # to child process
    # using os.kill() method
    # SIGCONT signal will cause
    # the child process to continue
    os.kill(pid, signal.SIGCONT)
  
    # Get the child's pid and 
    # status code using
    # os.waitpid() method
    info = os.waitpid(pid, os.WCONTINUED)
  
    # info is a tuple
    # info[0] represents child's pid
    # info[1] represents exit status code
  
    print("\nIn parent process")
      
    # Check whether the child process
    # has been continued 
    # from a job control stop or not    
    # using os.WIFCONTINUED() method
    continued = os.WIFCONTINUED(info[1]) 
  
    print("Has child process been continued from a job control stop?")
    print(continued)
  
  
else :
  
    print("In Child process")
    print("Process ID:", os.getpid())
    print("Hello ! Geeks")
         

输出:

In Child process
Process ID: 12371
Hello! Geeks

In parent process
Has child process been continued from a job control stop?
True

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程