Re: current_proc() issue on leopard
Re: current_proc() issue on leopard
- Subject: Re: current_proc() issue on leopard
- From: Terry Lambert <email@hidden>
- Date: Thu, 20 Mar 2008 15:29:28 -0700
On Mar 20, 2008, at 2:34 AM, Quinn wrote:
At 14:38 +0530 20/3/08, Praveen Kumar wrote:
The following code gives the current process name.
struct proc *p = current_proc();
p->p_comm // contains current process name
On Tiger, it is working fine, but on leopard, p_comm is empty.
Please let me know if there are alternate ways to get the current
process name.
(struct proc) is private, and has been since 10.4. You should /not/
be trying to access fields within it. In fact, I'm confused as to
how this even compiles!
Fortunately, there is a much better way to do this. Check out
proc_name defined in <sys/proc.h> in the Kernel framework.
Also, proc_self (from the same header) is a more modern way to get
the current process. If you switch to that, please note that it
gives you a reference to the current process that you then have to
release using proc_rele.
There is also the KPI function proc_selfname(), which returns the name
of the current process in a string buffer supplied by the caller.
Note that Mike Smith's point about no using the name to make any
decisions, particularly security decisions, is a good one.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden