import linecache


def pid_to_ngid_linux(pid):
    """ Get NGID of a process by its PID on Linux. Used as the PID on host for a process inside a container. """
    try:
        line = linecache.getline(f'/proc/{pid}/status', 5)
        ngid = line.strip().split()[1]
        ngid = int(ngid)
    except Exception: #pylint: disable=broad-except
        ngid = pid
    return ngid or pid