Re: Process id recycling and status of tasks

From: Clemens Ladisch
Date: Fri Oct 23 2009 - 04:13:45 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/