[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f22d86810910241107l21159ccdx2203e2b537b7f36@mail.gmail.com>
Date: Sat, 24 Oct 2009 23:37:22 +0530
From: "Leonidas ." <leonidas137@...il.com>
To: Clemens Ladisch <clemens@...isch.de>
Cc: linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: Process id recycling and status of tasks
On Fri, Oct 23, 2009 at 1:43 PM, Clemens Ladisch <clemens@...isch.de> wrote:
> Leonidas . wrote:
>> 1. What would be an ideal way to check if a task is alive or dead from
>> kernel space?
>
> Get a reference to the task's pid (call get_task_pid(), or get_pid() on
> the return value of task_pid()), then later check whether pid_task()
> works.
>
> (pid_alive() is not what you want because this would require that you
> hold a reference to the task_struct.)
>
>> even though a certain pid might exist, it might have got recycled by
>> the time I check again, right?
>
> The functions above do not work with PID numbers but with struct pid
> which is a reference-counted object. (The functions with "get" in their
> name increase the reference count, so don't forget to put_pid() when you
> no longer need it.) See also the big comment in include/linux/pid.h.
>
>
> HTH
> Clemens
>
Yes, the comment in pid.h says it.
Was going through pid.c, what is the fundamental difference between pid_task()
and get_pid_task()? Is it correct to say that, get_pid_task() will
check whether the
task struct is stale or not and return accordingly and pid_task() will
blindly return
task_struct which might be stale?
Now my understanding is get_pid_task() should be followed by put_pid_task()
so the reference counting work as expected, but put_pid_task() is not an
exported symbol? Am I missing here something?
The obvious question which follows from above is what would be the correct
way to determine whether a process is alive or not using pid_alive()? Using
pid_task() does not seem correct and seemingly correct way looks unfeasible.
-Leo.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists