About the pkill command, I know is possible kill processes - for specific scenarios - based through tty[1-6] and pts/[0-N]. I tested and works as expected. Until here all is ok.

But now, according with this answer and solution:

it indicates (extraction):

pkill and killall are also wrappers to the kill system call, (actually, to the libc library which directly invokes the system call), but can determine the PIDs for you, based on things like, process name, owner of the process, session id, etc.

Observe the session id part. I did do check both man and only exists this feature for pkill according with any of:

as follows respectively:

-s sid,...
Only match processes whose process session ID is listed. 
Session ID 0 is translated into pgrep's or pkill's own session ID.

-s, --session sid,...
Only match processes whose process session ID is listed. 
Session ID 0 is translated into pgrep's or pkill's own session ID.

As you can see the content is the same with a minor variation in the options/parameters names.

If I use:

  • directly the console, therefore is possible use pkill based on tty[1-6] to kill something
  • a remote connection through ssh, therefore is possible use pkill based on pts/[0-N] to kill something.

The reason of this post:


  • What does Session ID mean within the pkill context?

Extra Questions

  • How was a Session ID created?
  • How to know/retrieve a list of Sessions ID to be used for pkill?

1 Answer 1


The session id is the identifier of a process’ session. Sessions are a concept tied to shell job control, at a level above process groups; all processes in a given session share the same controlling terminal. In non-graphical environments, sessions can be thought of as login sessions (at least, that’s part of the original idea; they mustn’t be confused with systemd sessions which track login sessions in systemd-based environments).

Sessions are created with a call to setsid; see also their description in man credentials. Those links are to Linux-specific documentation, but this isn’t Linux-specific; see also the POSIX specification for setsid.

ps can show session ids:

ps -eo pid,sess,args
  • I assumed it was a special kind of connection, something "similar" than tty/pst, but since you did mention of the setsid method - it seems it is accomplish manually. Am I correct? May 3, 2022 at 14:05
  • Why would be mandatory or need it use the setid method? May 3, 2022 at 14:15
  • 1
    I’m not sure what you have in mind with tty/pst (tty/pts?). Processes which care about terminals will take care of pts etc., and processes which care about sessions might need to call setsid. One common reason to call setsid is to ensure that the process has its own controlling terminal (or none at all), so that it doesn’t get a SIGHUP related to something else closing; see Why we use setsid() while daemonizing a process? for example. May 3, 2022 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .