mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Leonidas ." <leonidas137@gmail.com>
To: Clemens Ladisch <clemens@ladisch.de>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Process id recycling and status of tasks
Date: Sat, 24 Oct 2009 23:37:22 +0530	[thread overview]
Message-ID: <f22d86810910241107l21159ccdx2203e2b537b7f36@mail.gmail.com> (raw)
In-Reply-To: <4AE165A4.70706@ladisch.de>

On Fri, Oct 23, 2009 at 1:43 PM, Clemens Ladisch <clemens@ladisch.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.

  reply	other threads:[~2009-10-24 18:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-22 13:29 Leonidas .
2009-10-23  8:13 ` Clemens Ladisch
2009-10-24 18:07   ` Leonidas . [this message]
2009-10-25 10:49     ` Leonidas .
2009-10-26  8:41     ` Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f22d86810910241107l21159ccdx2203e2b537b7f36@mail.gmail.com \
    --to=leonidas137@gmail.com \
    --cc=clemens@ladisch.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®