本文整理匯總了Python中os.getsid方法的典型用法代碼示例。如果您正苦於以下問題:Python os.getsid方法的具體用法?Python os.getsid怎麽用?Python os.getsid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os
的用法示例。
在下文中一共展示了os.getsid方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _check_ioctl_mutate_len
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def _check_ioctl_mutate_len(self, nbytes=None):
buf = array.array('i')
intsize = buf.itemsize
ids = (os.getpgrp(), os.getsid(0))
# A fill value unlikely to be in `ids`
fill = -12345
if nbytes is not None:
# Extend the buffer so that it is exactly `nbytes` bytes long
buf.extend([fill] * (nbytes // intsize))
self.assertEqual(len(buf) * intsize, nbytes) # sanity check
else:
buf.append(fill)
with open("/dev/tty", "r") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEqual(r, 0)
self.assertIn(rpgrp, ids)
示例2: kill_em_all
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def kill_em_all(sig, frame):
"""
Terminate all processes while capturing a SIGINT from the user
"""
logger_gen.info('CTRL-C received, exiting')
if is_windows():
multiprocessing.sys.exit(1)
else:
pid = os.getpid()
pgid = os.getpgid(pid)
sid = os.getsid(os.getpid())
# if launched with --no-xserver
if pid == sid:
os.killpg(pgid, signal.SIGKILL)
else:
time.sleep(4)
multiprocessing.sys.exit(1)
示例3: _check_ioctl_mutate_len
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def _check_ioctl_mutate_len(self, nbytes=None):
buf = array.array('i')
intsize = buf.itemsize
ids = (os.getpgrp(), os.getsid(0))
# A fill value unlikely to be in `ids`
fill = -12345
if nbytes is not None:
# Extend the buffer so that it is exactly `nbytes` bytes long
buf.extend([fill] * (nbytes // intsize))
self.assertEqual(len(buf) * intsize, nbytes) # sanity check
else:
buf.append(fill)
with open("/dev/tty", "rb") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEqual(r, 0)
self.assertIn(rpgrp, ids)
示例4: test_ioctl
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assertIn(rpgrp, ids)
示例5: test_ioctl
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
with open("/dev/tty", "rb") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assertIn(rpgrp, ids)
示例6: get_sid
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def get_sid(self):
""" return the CURRENT session id of the process. this differs from
self.sid in that this refects the current state of the process, where
self.sid is the session id at launch """
return os.getsid(self.pid)
示例7: childproc_filialusurp
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def childproc_filialusurp(umask, chdir, umask_path, sid_path, wdir_path,
pid_path):
_filial_usurpation(chdir, umask)
# Get our session id
my_pid = os.getpid()
sid = os.getsid(my_pid)
# reset umask and get our set one.
umask = os.umask(0)
# Get our working directory.
wdir = os.path.abspath(os.getcwd())
# Update parent
# Write the umask to the response path
with open(umask_path, 'w') as f:
f.write(str(umask) + '\n')
# Write the sid to the response path
with open(sid_path, 'w') as f:
f.write(str(sid) + '\n')
# Write the working dir to the response path
with open(wdir_path, 'w') as f:
f.write(wdir + '\n')
# Write the pid to the response path
with open(pid_path, 'w') as f:
f.write(str(my_pid) + '\n')
# ###############################################
# Testing
# ###############################################
示例8: test_ioctl
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
示例9: test_ioctl_mutate
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def test_ioctl_mutate(self):
import array
buf = array.array('i', [0])
ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEquals(r, 0)
self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
示例10: close
# 需要導入模塊: import os [as 別名]
# 或者: from os import getsid [as 別名]
def close(self) -> None:
if self.closed:
raise channel.ChannelClosedException()
sid = os.getsid(self.p.pid)
self.p.terminate()
os.close(self.pty_master)
self.p.wait()
# Wait for all processes in the session to end. Most of the time
# this will return immediately, but in some cases (eg. a serial session
# with picocom) we have to wait a bit until we can continue. To be as
# quick as possible this is implemented as exponential backoff and will
# give up after 1 second (1.27 to be exact) and emit a warning.
for t in range(7):
if (
subprocess.call(
["ps", "-s", str(sid)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
!= 0
):
break
time.sleep(2 ** t / 100)
else:
raise Exception("not done")