We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
2 doctests in proc fail on debian
We have some tests that assume pid 1 is init , and they fail on debian versions that use systemd. I can't really think of tests that are less platform-specific, any suggestions?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pwnlib/util/proc.py`
Content:
```
1 import time, errno, logging
2 from .. import tubes
3 
4 try:
5     import psutil
6     _ok_import = True
7 except ImportError:
8     _ok_import = False
9 
10 log = logging.getLogger(__name__)
11 
12 if _ok_import:
13     all_pids = psutil.pids
14 
15 def pidof(target):
16     """pidof(target) -> int list
17 
18     Get PID(s) of `target`.  The returned PID(s) depends on the type of `target`:
19 
20         - :class:`str`: PIDs of all processes with a name matching `target`.
21 
22         - :class:`pwnlib.tubes.process.process`: singleton list of the PID of `target`.
23 
24         - :class:`pwnlib.tubes.sock.sock`: singleton list of the PID at the
25         remote end of `target` if it is running on the host.  Otherwise an
26         empty list.
27 
28     Args:
29         target(object):  The target whose PID(s) to find.
30 
31     Returns:
32         A list of found PIDs.
33     """
34     if isinstance(target, tubes.sock.sock):
35          local  = target.sock.getsockname()
36          remote = target.sock.getpeername()
37 
38          def match(p):
39              return (c.raddr, c.laddr, c.status) == (local, remote, 'ESTABLISHED')
40 
41          return [c.pid for c in psutil.net_connections() if match(c)]
42 
43     elif isinstance(target, tubes.process.process):
44          return [target.proc.pid]
45 
46     else:
47          return pid_by_name(target)
48 
49 def pid_by_name(name):
50     """pid_by_name(name) -> int list
51 
52     Args:
53         name (str): Name of program.
54 
55     Returns:
56         List of PIDs matching `name` sorted by lifetime, youngest to oldest.
57 
58     Example:
59         >>> 1 in pid_by_name('init')
60         True
61         >>> os.getpid() in pid_by_name(name(os.getpid()))
62         True
63     """
64     def match(p):
65          if p.name() == name:
66              return True
67          try:
68              if p.exe() == name:
69                  return True
70          except:
71              pass
72          return False
73 
74     return [p.pid for p in psutil.process_iter() if match(p)]
75 
76 def name(pid):
77     """name(pid) -> str
78 
79     Args:
80         pid (int): PID of the process.
81 
82     Returns:
83         Name of process as listed in ``/proc/<pid>/status``.
84 
85     Example:
86         >>> name(1)
87         'init'
88     """
89     return psutil.Process(pid).name()
90 
91 def parent(pid):
92     """parent(pid) -> int
93 
94     Args:
95         pid (int): PID of the process.
96 
97     Returns:
98         Parent PID as listed in ``/proc/<pid>/status`` under ``PPid``,
99         or 0 if there is not parent.
100     """
101     try:
102          return psutil.Process(pid).parent().pid
103     except:
104          return 0
105 
106 def children(ppid):
107     """children(ppid) -> int list
108 
109     Args:
110         pid (int): PID of the process.
111 
112     Returns:
113         List of PIDs of whose parent process is `pid`.
114     """
115     return [p.pid for p in psutil.Process(ppid).children()]
116 
117 def ancestors(pid):
118     """ancestors(pid) -> int list
119 
120     Args:
121         pid (int): PID of the process.
122 
123     Returns:
124         List of PIDs of whose parent process is `pid` or an ancestor of `pid`.
125     """
126     pids = []
127     while pid != 0:
128          pids.append(pid)
129          pid = parent(pid)
130     return pids
131 
132 def descendants(pid):
133     """descendants(pid) -> dict
134 
135     Args:
136         pid (int): PID of the process.
137 
138     Returns:
139         Dictionary mapping the PID of each child of `pid` to it's descendants.
140     """
141     this_pid = pid
142     allpids = all_pids()
143     ppids = {}
144     def _parent(pid):
145          if pid not in ppids:
146              ppids[pid] = parent(pid)
147          return ppids[pid]
148     def _children(ppid):
149          return [pid for pid in allpids if _parent(pid) == ppid]
150     def _loop(ppid):
151          return {pid: _loop(pid) for pid in _children(ppid)}
152     return _loop(pid)
153 
154 def exe(pid):
155     """exe(pid) -> str
156 
157     Args:
158         pid (int): PID of the process.
159 
160     Returns:
161         The path of the binary of the process. I.e. what ``/proc/<pid>/exe`` points to.
162     """
163     return psutil.Process(pid).exe()
164 
165 def cwd(pid):
166     """cwd(pid) -> str
167 
168     Args:
169         pid (int): PID of the process.
170 
171     Returns:
172         The path of the process's current working directory. I.e. what
173         ``/proc/<pid>/cwd`` points to.
174     """
175     return psutil.Process(pid).cwd()
176 
177 def cmdline(pid):
178     """cmdline(pid) -> str list
179 
180     Args:
181         pid (int): PID of the process.
182 
183     Returns:
184         A list of the fields in ``/proc/<pid>/cmdline``.
185     """
186     return psutil.Process(pid).cmdline()
187 
188 def stat(pid):
189     """stat(pid) -> str list
190 
191     Args:
192         pid (int): PID of the process.
193 
194     Returns:
195         A list of the values in ``/proc/<pid>/stat``, with the exception that ``(`` and ``)`` has been removed from around the process name.
196     """
197     with open('/proc/%d/stat' % pid) as fd:
198          s = fd.read()
199     # filenames can have ( and ) in them, dammit
200     i = s.find('(')
201     j = s.rfind(')')
202     name = s[i+1:j]
203     return s[:i].split() + [name] + s[j+1:].split()
204 
205 def starttime(pid):
206     """starttime(pid) -> float
207 
208     Args:
209         pid (int): PID of the process.
210 
211     Returns:
212         The time (in seconds) the process started after system boot
213     """
214     return psutil.Process(pid).create_time() - psutil.boot_time()
215 
216 def status(pid):
217     """status(pid) -> dict
218 
219     Get the status of a process.
220 
221     Args:
222         pid (int): PID of the process.
223 
224     Returns:
225         The contents of ``/proc/<pid>/status`` as a dictionary.
226     """
227     out = {}
228     try:
229         with open('/proc/%d/status' % pid) as fd:
230             for line in fd:
231                 i = line.index(':')
232                 key = line[:i]
233                 val = line[i + 2:-1] # initial :\t and trailing \n
234                 out[key] = val
235     except OSError as e:
236         if e.errno == errno.ENOENT:
237             raise ValueError('No process with PID %d' % pid)
238         else:
239             raise
240     return out
241 
242 def tracer(pid):
243     """tracer(pid) -> int
244 
245     Args:
246         pid (int): PID of the process.
247 
248     Returns:
249         PID of the process tracing `pid`, or None if no `pid` is not being traced.
250 
251     Example:
252         >>> tracer(os.getpid()) is None
253         True
254     """
255     tpid = int(status(pid)['TracerPid'])
256     return tpid if tpid > 0 else None
257 
258 def state(pid):
259     """state(pid) -> str
260 
261     Args:
262         pid (int): PID of the process.
263 
264     Returns:
265         State of the process as listed in ``/proc/<pid>/status``.  See `proc(5)` for details.
266 
267     Example:
268         >>> state(os.getpid())
269         'R (running)'
270     """
271     return status(pid)['State']
272 
273 def wait_for_debugger(pid):
274     """wait_for_debugger(pid) -> None
275 
276     Sleeps until the process with PID `pid` is being traced.
277 
278     Args:
279         pid (int): PID of the process.
280 
281     Returns:
282         None
283     """
284     with log.waitfor('Waiting for debugger') as l:
285         while tracer(pid) is None:
286             time.sleep(0.01)
287         l.success()
288 
289 if not _ok_import:
290     def _make_stub(func):
291         func.__doc__ = 'Stubbed out function, because psutil is not available.'
292         return func
293 
294     @_make_stub
295     def all_pids():
296         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
297 
298     @_make_stub
299     def pidof(target):
300         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
301 
302     @_make_stub
303     def pid_by_name(name):
304         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
305 
306     @_make_stub
307     def name(pid):
308         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
309 
310     @_make_stub
311     def parent(pid):
312         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
313 
314     @_make_stub
315     def children(ppid):
316         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
317 
318     @_make_stub
319     def ancestors(pid):
320         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
321 
322     @_make_stub
323     def descendants(pid):
324         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
325 
326     @_make_stub
327     def exe(pid):
328         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
329 
330     @_make_stub
331     def cwd(pid):
332         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
333 
334     @_make_stub
335     def cmdline(pid):
336         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
337 
338     @_make_stub
339     def starttime(pid):
340         log.error("Called stubbed-out function. Get psutil to work on your platform, then come back.")
341
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pwnlib/util/proc.py b/pwnlib/util/proc.py
--- a/pwnlib/util/proc.py
+++ b/pwnlib/util/proc.py
@@ -56,8 +56,6 @@
         List of PIDs matching `name` sorted by lifetime, youngest to oldest.
 
     Example:
-        >>> 1 in pid_by_name('init')
-        True
         >>> os.getpid() in pid_by_name(name(os.getpid()))
         True
     """
@@ -83,8 +81,8 @@
         Name of process as listed in ``/proc/<pid>/status``.
 
     Example:
-        >>> name(1)
-        'init'
+        >>> name(os.getpid()) == os.path.basename(sys.argv[0])
+        True
     """
     return psutil.Process(pid).name()

{"golden_diff": "diff --git a/pwnlib/util/proc.py b/pwnlib/util/proc.py\n--- a/pwnlib/util/proc.py\n+++ b/pwnlib/util/proc.py\n@@ -56,8 +56,6 @@\n         List of PIDs matching `name` sorted by lifetime, youngest to oldest.\n \n     Example:\n-        >>> 1 in pid_by_name('init')\n-        True\n         >>> os.getpid() in pid_by_name(name(os.getpid()))\n         True\n     \"\"\"\n@@ -83,8 +81,8 @@\n         Name of process as listed in ``/proc/<pid>/status``.\n \n     Example:\n-        >>> name(1)\n-        'init'\n+        >>> name(os.getpid()) == os.path.basename(sys.argv[0])\n+        True\n     \"\"\"\n     return psutil.Process(pid).name()\n", "issue": "2 doctests in proc fail on debian\nWe have some tests that assume pid 1 is init , and they fail on debian versions that use systemd. I can't really think of tests that are less platform-specific, any suggestions?\n\n", "before_files": [{"content": "import time, errno, logging\nfrom .. import tubes\n\ntry:\n    import psutil\n    _ok_import = True\nexcept ImportError:\n    _ok_import = False\n\nlog = logging.getLogger(__name__)\n\nif _ok_import:\n    all_pids = psutil.pids\n\ndef pidof(target):\n    \"\"\"pidof(target) -> int list\n\n    Get PID(s) of `target`.  The returned PID(s) depends on the type of `target`:\n\n        - :class:`str`: PIDs of all processes with a name matching `target`.\n\n        - :class:`pwnlib.tubes.process.process`: singleton list of the PID of `target`.\n\n        - :class:`pwnlib.tubes.sock.sock`: singleton list of the PID at the\n        remote end of `target` if it is running on the host.  Otherwise an\n        empty list.\n\n    Args:\n        target(object):  The target whose PID(s) to find.\n\n    Returns:\n        A list of found PIDs.\n    \"\"\"\n    if isinstance(target, tubes.sock.sock):\n         local  = target.sock.getsockname()\n         remote = target.sock.getpeername()\n\n         def match(p):\n             return (c.raddr, c.laddr, c.status) == (local, remote, 'ESTABLISHED')\n\n         return [c.pid for c in psutil.net_connections() if match(c)]\n\n    elif isinstance(target, tubes.process.process):\n         return [target.proc.pid]\n\n    else:\n         return pid_by_name(target)\n\ndef pid_by_name(name):\n    \"\"\"pid_by_name(name) -> int list\n\n    Args:\n        name (str): Name of program.\n\n    Returns:\n        List of PIDs matching `name` sorted by lifetime, youngest to oldest.\n\n    Example:\n        >>> 1 in pid_by_name('init')\n        True\n        >>> os.getpid() in pid_by_name(name(os.getpid()))\n        True\n    \"\"\"\n    def match(p):\n         if p.name() == name:\n             return True\n         try:\n             if p.exe() == name:\n                 return True\n         except:\n             pass\n         return False\n\n    return [p.pid for p in psutil.process_iter() if match(p)]\n\ndef name(pid):\n    \"\"\"name(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Name of process as listed in ``/proc/<pid>/status``.\n\n    Example:\n        >>> name(1)\n        'init'\n    \"\"\"\n    return psutil.Process(pid).name()\n\ndef parent(pid):\n    \"\"\"parent(pid) -> int\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Parent PID as listed in ``/proc/<pid>/status`` under ``PPid``,\n        or 0 if there is not parent.\n    \"\"\"\n    try:\n         return psutil.Process(pid).parent().pid\n    except:\n         return 0\n\ndef children(ppid):\n    \"\"\"children(ppid) -> int list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        List of PIDs of whose parent process is `pid`.\n    \"\"\"\n    return [p.pid for p in psutil.Process(ppid).children()]\n\ndef ancestors(pid):\n    \"\"\"ancestors(pid) -> int list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        List of PIDs of whose parent process is `pid` or an ancestor of `pid`.\n    \"\"\"\n    pids = []\n    while pid != 0:\n         pids.append(pid)\n         pid = parent(pid)\n    return pids\n\ndef descendants(pid):\n    \"\"\"descendants(pid) -> dict\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Dictionary mapping the PID of each child of `pid` to it's descendants.\n    \"\"\"\n    this_pid = pid\n    allpids = all_pids()\n    ppids = {}\n    def _parent(pid):\n         if pid not in ppids:\n             ppids[pid] = parent(pid)\n         return ppids[pid]\n    def _children(ppid):\n         return [pid for pid in allpids if _parent(pid) == ppid]\n    def _loop(ppid):\n         return {pid: _loop(pid) for pid in _children(ppid)}\n    return _loop(pid)\n\ndef exe(pid):\n    \"\"\"exe(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The path of the binary of the process. I.e. what ``/proc/<pid>/exe`` points to.\n    \"\"\"\n    return psutil.Process(pid).exe()\n\ndef cwd(pid):\n    \"\"\"cwd(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The path of the process's current working directory. I.e. what\n        ``/proc/<pid>/cwd`` points to.\n    \"\"\"\n    return psutil.Process(pid).cwd()\n\ndef cmdline(pid):\n    \"\"\"cmdline(pid) -> str list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        A list of the fields in ``/proc/<pid>/cmdline``.\n    \"\"\"\n    return psutil.Process(pid).cmdline()\n\ndef stat(pid):\n    \"\"\"stat(pid) -> str list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        A list of the values in ``/proc/<pid>/stat``, with the exception that ``(`` and ``)`` has been removed from around the process name.\n    \"\"\"\n    with open('/proc/%d/stat' % pid) as fd:\n         s = fd.read()\n    # filenames can have ( and ) in them, dammit\n    i = s.find('(')\n    j = s.rfind(')')\n    name = s[i+1:j]\n    return s[:i].split() + [name] + s[j+1:].split()\n\ndef starttime(pid):\n    \"\"\"starttime(pid) -> float\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The time (in seconds) the process started after system boot\n    \"\"\"\n    return psutil.Process(pid).create_time() - psutil.boot_time()\n\ndef status(pid):\n    \"\"\"status(pid) -> dict\n\n    Get the status of a process.\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The contents of ``/proc/<pid>/status`` as a dictionary.\n    \"\"\"\n    out = {}\n    try:\n        with open('/proc/%d/status' % pid) as fd:\n            for line in fd:\n                i = line.index(':')\n                key = line[:i]\n                val = line[i + 2:-1] # initial :\\t and trailing \\n\n                out[key] = val\n    except OSError as e:\n        if e.errno == errno.ENOENT:\n            raise ValueError('No process with PID %d' % pid)\n        else:\n            raise\n    return out\n\ndef tracer(pid):\n    \"\"\"tracer(pid) -> int\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        PID of the process tracing `pid`, or None if no `pid` is not being traced.\n\n    Example:\n        >>> tracer(os.getpid()) is None\n        True\n    \"\"\"\n    tpid = int(status(pid)['TracerPid'])\n    return tpid if tpid > 0 else None\n\ndef state(pid):\n    \"\"\"state(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        State of the process as listed in ``/proc/<pid>/status``.  See `proc(5)` for details.\n\n    Example:\n        >>> state(os.getpid())\n        'R (running)'\n    \"\"\"\n    return status(pid)['State']\n\ndef wait_for_debugger(pid):\n    \"\"\"wait_for_debugger(pid) -> None\n\n    Sleeps until the process with PID `pid` is being traced.\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        None\n    \"\"\"\n    with log.waitfor('Waiting for debugger') as l:\n        while tracer(pid) is None:\n            time.sleep(0.01)\n        l.success()\n\nif not _ok_import:\n    def _make_stub(func):\n        func.__doc__ = 'Stubbed out function, because psutil is not available.'\n        return func\n\n    @_make_stub\n    def all_pids():\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def pidof(target):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def pid_by_name(name):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def name(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def parent(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def children(ppid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def ancestors(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def descendants(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def exe(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def cwd(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def cmdline(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def starttime(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n", "path": "pwnlib/util/proc.py"}], "after_files": [{"content": "import time, errno, logging\nfrom .. import tubes\n\ntry:\n    import psutil\n    _ok_import = True\nexcept ImportError:\n    _ok_import = False\n\nlog = logging.getLogger(__name__)\n\nif _ok_import:\n    all_pids = psutil.pids\n\ndef pidof(target):\n    \"\"\"pidof(target) -> int list\n\n    Get PID(s) of `target`.  The returned PID(s) depends on the type of `target`:\n\n        - :class:`str`: PIDs of all processes with a name matching `target`.\n\n        - :class:`pwnlib.tubes.process.process`: singleton list of the PID of `target`.\n\n        - :class:`pwnlib.tubes.sock.sock`: singleton list of the PID at the\n        remote end of `target` if it is running on the host.  Otherwise an\n        empty list.\n\n    Args:\n        target(object):  The target whose PID(s) to find.\n\n    Returns:\n        A list of found PIDs.\n    \"\"\"\n    if isinstance(target, tubes.sock.sock):\n         local  = target.sock.getsockname()\n         remote = target.sock.getpeername()\n\n         def match(p):\n             return (c.raddr, c.laddr, c.status) == (local, remote, 'ESTABLISHED')\n\n         return [c.pid for c in psutil.net_connections() if match(c)]\n\n    elif isinstance(target, tubes.process.process):\n         return [target.proc.pid]\n\n    else:\n         return pid_by_name(target)\n\ndef pid_by_name(name):\n    \"\"\"pid_by_name(name) -> int list\n\n    Args:\n        name (str): Name of program.\n\n    Returns:\n        List of PIDs matching `name` sorted by lifetime, youngest to oldest.\n\n    Example:\n        >>> os.getpid() in pid_by_name(name(os.getpid()))\n        True\n    \"\"\"\n    def match(p):\n         if p.name() == name:\n             return True\n         try:\n             if p.exe() == name:\n                 return True\n         except:\n             pass\n         return False\n\n    return [p.pid for p in psutil.process_iter() if match(p)]\n\ndef name(pid):\n    \"\"\"name(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Name of process as listed in ``/proc/<pid>/status``.\n\n    Example:\n        >>> name(os.getpid()) == os.path.basename(sys.argv[0])\n        True\n    \"\"\"\n    return psutil.Process(pid).name()\n\ndef parent(pid):\n    \"\"\"parent(pid) -> int\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Parent PID as listed in ``/proc/<pid>/status`` under ``PPid``,\n        or 0 if there is not parent.\n    \"\"\"\n    try:\n         return psutil.Process(pid).parent().pid\n    except:\n         return 0\n\ndef children(ppid):\n    \"\"\"children(ppid) -> int list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        List of PIDs of whose parent process is `pid`.\n    \"\"\"\n    return [p.pid for p in psutil.Process(ppid).children()]\n\ndef ancestors(pid):\n    \"\"\"ancestors(pid) -> int list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        List of PIDs of whose parent process is `pid` or an ancestor of `pid`.\n    \"\"\"\n    pids = []\n    while pid != 0:\n         pids.append(pid)\n         pid = parent(pid)\n    return pids\n\ndef descendants(pid):\n    \"\"\"descendants(pid) -> dict\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        Dictionary mapping the PID of each child of `pid` to it's descendants.\n    \"\"\"\n    this_pid = pid\n    allpids = all_pids()\n    ppids = {}\n    def _parent(pid):\n         if pid not in ppids:\n             ppids[pid] = parent(pid)\n         return ppids[pid]\n    def _children(ppid):\n         return [pid for pid in allpids if _parent(pid) == ppid]\n    def _loop(ppid):\n         return {pid: _loop(pid) for pid in _children(ppid)}\n    return _loop(pid)\n\ndef exe(pid):\n    \"\"\"exe(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The path of the binary of the process. I.e. what ``/proc/<pid>/exe`` points to.\n    \"\"\"\n    return psutil.Process(pid).exe()\n\ndef cwd(pid):\n    \"\"\"cwd(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The path of the process's current working directory. I.e. what\n        ``/proc/<pid>/cwd`` points to.\n    \"\"\"\n    return psutil.Process(pid).cwd()\n\ndef cmdline(pid):\n    \"\"\"cmdline(pid) -> str list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        A list of the fields in ``/proc/<pid>/cmdline``.\n    \"\"\"\n    return psutil.Process(pid).cmdline()\n\ndef stat(pid):\n    \"\"\"stat(pid) -> str list\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        A list of the values in ``/proc/<pid>/stat``, with the exception that ``(`` and ``)`` has been removed from around the process name.\n    \"\"\"\n    with open('/proc/%d/stat' % pid) as fd:\n         s = fd.read()\n    # filenames can have ( and ) in them, dammit\n    i = s.find('(')\n    j = s.rfind(')')\n    name = s[i+1:j]\n    return s[:i].split() + [name] + s[j+1:].split()\n\ndef starttime(pid):\n    \"\"\"starttime(pid) -> float\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The time (in seconds) the process started after system boot\n    \"\"\"\n    return psutil.Process(pid).create_time() - psutil.boot_time()\n\ndef status(pid):\n    \"\"\"status(pid) -> dict\n\n    Get the status of a process.\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        The contents of ``/proc/<pid>/status`` as a dictionary.\n    \"\"\"\n    out = {}\n    try:\n        with open('/proc/%d/status' % pid) as fd:\n            for line in fd:\n                i = line.index(':')\n                key = line[:i]\n                val = line[i + 2:-1] # initial :\\t and trailing \\n\n                out[key] = val\n    except OSError as e:\n        if e.errno == errno.ENOENT:\n            raise ValueError('No process with PID %d' % pid)\n        else:\n            raise\n    return out\n\ndef tracer(pid):\n    \"\"\"tracer(pid) -> int\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        PID of the process tracing `pid`, or None if no `pid` is not being traced.\n\n    Example:\n        >>> tracer(os.getpid()) is None\n        True\n    \"\"\"\n    tpid = int(status(pid)['TracerPid'])\n    return tpid if tpid > 0 else None\n\ndef state(pid):\n    \"\"\"state(pid) -> str\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        State of the process as listed in ``/proc/<pid>/status``.  See `proc(5)` for details.\n\n    Example:\n        >>> state(os.getpid())\n        'R (running)'\n    \"\"\"\n    return status(pid)['State']\n\ndef wait_for_debugger(pid):\n    \"\"\"wait_for_debugger(pid) -> None\n\n    Sleeps until the process with PID `pid` is being traced.\n\n    Args:\n        pid (int): PID of the process.\n\n    Returns:\n        None\n    \"\"\"\n    with log.waitfor('Waiting for debugger') as l:\n        while tracer(pid) is None:\n            time.sleep(0.01)\n        l.success()\n\nif not _ok_import:\n    def _make_stub(func):\n        func.__doc__ = 'Stubbed out function, because psutil is not available.'\n        return func\n\n    @_make_stub\n    def all_pids():\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def pidof(target):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def pid_by_name(name):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def name(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def parent(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def children(ppid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def ancestors(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def descendants(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def exe(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def cwd(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def cmdline(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n\n    @_make_stub\n    def starttime(pid):\n        log.error(\"Called stubbed-out function. Get psutil to work on your platform, then come back.\")\n", "path": "pwnlib/util/proc.py"}]}