我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用os.getsid()。
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)
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)
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)
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)
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)
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 # ###############################################
def show_process_info(mark): print('\n') logging.info('show->%s',mark) # logging.info('sid:%s',os.getsid()) logging.info('gid:%s',os.getgid()) logging.info('pid:%s',os.getpid()) logging.info('uid:%s',os.getuid()) print('\n')
def sid(self): """ Session ID, or None if it hasn't started yet. POSIX only. """ return os.getsid(self.pid)