# Path: pgctl/errors.py
# class LockHeld(PgctlUserMessage):
#     """The pgctl supervision lock is held. This generally indicates subprocesses escaping supervision."""


import json
import os
import signal
import sys
import typing
    import atexit
from frozendict import frozendict
from .errors import LockHeld
        from os import getcwd
    from os.path import relpath
    from .subprocess import PIPE, Popen
    from .fuser import fuser
    from py._error import error as pylib_error
        from .subprocess import check_call
    """Return a relative path only if it's under $PWD (or `relto`)"""
    if relto is None:
        relto = getcwd()
    relpath = relpath(path, relto)
    if relpath.startswith('.'):
        return path
    else:
        return relpath


def ps(pids):
    """Give a (somewhat) human-readable printout of a list of processes"""
    pids = tuple(str(pid) for pid in pids)
    if not pids:
        return ''

    cmd = ('ps', '--forest', '-wwfj',) + pids
    process = Popen(cmd, stdout=PIPE, stderr=PIPE)
    stdout, _ = process.communicate()
    stdout = stdout.decode('UTF-8')
    if stdout.count('\n') > 1:
        return stdout
    else:
        # race condition: we only got the ps -f header
        return ''  # pragma: no cover, we don't expect to hit this


def show_runaway_processes(path):
    processes = ps(fuser(path))
    if processes:

# Path: pgctl/errors.py
# class LockHeld(PgctlUserMessage):
#     """The pgctl supervision lock is held. This generally indicates subprocesses escaping supervision."""


# Path: pgctl/functions.py
import json
import os
import signal
import sys
import typing
    import atexit
from frozendict import frozendict
from .errors import LockHeld
        from os import getcwd
    from os.path import relpath
    from .subprocess import PIPE, Popen
    from .fuser import fuser
    from py._error import error as pylib_error
        from .subprocess import check_call

    """Return a relative path only if it's under $PWD (or `relto`)"""
    if relto is None:
        relto = getcwd()
    relpath = relpath(path, relto)
    if relpath.startswith('.'):
        return path
    else:
        return relpath


def ps(pids):
    """Give a (somewhat) human-readable printout of a list of processes"""
    pids = tuple(str(pid) for pid in pids)
    if not pids:
        return ''

    cmd = ('ps', '--forest', '-wwfj',) + pids
    process = Popen(cmd, stdout=PIPE, stderr=PIPE)
    stdout, _ = process.communicate()
    stdout = stdout.decode('UTF-8')
    if stdout.count('\n') > 1:
        return stdout
    else:
        # race condition: we only got the ps -f header
        return ''  # pragma: no cover, we don't expect to hit this


def show_runaway_processes(path):
    processes = ps(fuser(path))
    if processes:

        raise LockHeld(