MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / fork

Function fork

tools/python-3.11.9-amd64/Lib/pty.py:84–122  ·  view source on GitHub ↗

fork() -> (pid, master_fd) Fork and make the child a session leader with a controlling terminal.

()

Source from the content-addressed store, hash-verified

82 return result
83
84def fork():
85 """fork() -> (pid, master_fd)
86 Fork and make the child a session leader with a controlling terminal."""
87
88 try:
89 pid, fd = os.forkpty()
90 except (AttributeError, OSError):
91 pass
92 else:
93 if pid == CHILD:
94 try:
95 os.setsid()
96 except OSError:
97 # os.forkpty() already set us session leader
98 pass
99 return pid, fd
100
101 master_fd, slave_fd = openpty()
102 pid = os.fork()
103 if pid == CHILD:
104 # Establish a new session.
105 os.setsid()
106 os.close(master_fd)
107
108 # Slave becomes stdin/stdout/stderr of child.
109 os.dup2(slave_fd, STDIN_FILENO)
110 os.dup2(slave_fd, STDOUT_FILENO)
111 os.dup2(slave_fd, STDERR_FILENO)
112 if slave_fd > STDERR_FILENO:
113 os.close(slave_fd)
114
115 # Explicitly open the tty to make it become a controlling tty.
116 tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
117 os.close(tmp_fd)
118 else:
119 os.close(slave_fd)
120
121 # Parent and child process.
122 return pid, master_fd
123
124def _read(fd):
125 """Default read function."""

Callers 2

_spawnvefFunction · 0.85
spawnFunction · 0.85

Calls 3

openptyFunction · 0.85
closeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected