当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python os.WIFCONTINUED()用法及代码示例


Python中的OS模块提供了与操作系统进行交互的函数。操作系统属于Python的标准实用程序模块。该模块提供了使用依赖于操作系统的函数的便携式方法。

os.WIFCONTINUED()Python中的方法用于检查从作业控制停止是否继续执行某个过程。此方法采用流程状态代码,由os.wait()os.system()或者os.waitpid()方法作为参数,如果进程已停止,则返回True,否则返回False。

用法: os.WIFCONTINUED(status)

参数:
status:此参数采用os.system(),os.wait()方法或os.waitpid()方法返回的过程状态代码(整数值)。

返回类型:此方法返回“布尔”类的布尔值。如果从作业控制停止处继续执行该过程,则此方法返回True,否则返回False。

代码:用于os.WIFCONTINUED()方法

# 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

参考文献: https://docs.python.org/3/library/os.html#os.WIFCONTINUED



相关用法


注:本文由纯净天空筛选整理自ihritik大神的英文原创作品 Python | os.WIFCONTINUED() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。