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
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自ihritik大神的英文原創作品 Python | os.WIFCONTINUED() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。