New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: process group id and session id #697
Comments
Uhm... I am not sure these are portable across platforms; certainly not session id. |
@davidmankin you can get SID by Session ID is a PID(PGID) of the session leader. The concept was standardized by POSIX.1. SVR4, and BSD adopted it. So it's not Linux specific. Session manages Process Groups, Process Group manages Processes. Normally the shell is the session leader that interacts with the controlling terminal. In case of daemon process, it gets its own session after forking so it's detached from the invoking session. The use case of the group id is, say you want to group the processes that are piped together. They share the same PGID. |
OK, I read a bit about session/group IDs. As far as I understand this info is already available:
AFAIU |
This function doesn't actually show the |
pgid is about process groups where gids are about user group ids. The pgid could be used to know if a process is kernel or userland. For example, if you want to set affinity of all process on the system, you cannot do it on kernel pids, so you could use pgid to filter. |
Is there only a single process group ID? Or there can be multiple like >>> Process().pgid()
8225 Also, it would be good to understand whether "process groups" exist only on Linux or also on other POSIX platforms. I don't have time to investigate this right now (I'm traveling) so if somebody wants to at least steer direction that would be good (aka let's start a discussion before working on any implementation). |
As the first link suggest, it's an old UNIX concept. IIRC, the double fork for daemon is required to become the process group leader. From Wikipedia:
The link to to spec of getpgid in The Single UNIX ® Specification, Version 2: http://pubs.opengroup.org/onlinepubs/7990989775/xsh/getpgid.html Have a nice trip. |
OK, so it seems it's about 1 value only. As it has been previously said it is already possible to do this in pure python on a per-PID basis: >>> import os
>>> os.getpgid(os.getpid())
23948 ...which leads to the question whether it makes sense to duplicate the functionality in psutil (I'm not sure - I'll have to think about it). |
Ok, I was misled by the answer of @orodbhen. Actually, as you said, One interest to add it would be to benefit from psutil caching and being exported by |
On Linux, I need to be able to tell if any process in a group (or session) is still alive. Unfortunately
process_iter()
'sProcess
es don't have this information.This page says how to find the information on Linux; not sure about other platforms:
http://unix.stackexchange.com/questions/132224/is-it-possible-to-get-process-group-id-from-proc
The text was updated successfully, but these errors were encountered: