Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Jul 2007 23:23:45 -0400
From:      "Michael B Allen" <ioplex@gmail.com>
To:        freebsd-hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Path to executable of current process?
Message-ID:  <78c6bd860707192023u645a3c39ua713cc4384c3b876@mail.gmail.com>
In-Reply-To: <78c6bd860707191900g375f98ado8315603feac50247@mail.gmail.com>
References:  <78c6bd860707191725r14b8bfe3sf15c1f0e30cf82ca@mail.gmail.com> <78c6bd860707191900g375f98ado8315603feac50247@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> Is there any way to get argv[0] for [a particular] process without being root?

After more digging I see sysctl seems to be the way to do this but can I get
the full path to the executable form kinfo_proc?

How does ps do this?

static const char *
getcmdline(pid_t pid)
{
    static struct kinfo_proc ki_proc;
    int mib[4], len;

    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_PID;
    mib[3] = pid;

    len = sizeof(struct kinfo_proc);
    if (sysctl(mib, 4, &ki_proc, &len, NULL, 0) == -1)
        return NULL;

    return ki_proc.ki_???
}

Mike



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?78c6bd860707192023u645a3c39ua713cc4384c3b876>