4

If I wanted to know who is logged in since when and what are the processes currently running under his control, how can I do that in systemd?

drpaneas
  • 2,320

2 Answers2

6

You don't need systemd for that … but there's a systemd way of doing it as well, as long as you are running the systemd-logind daemon, or something that provides the same API.

First obtain a list of sessions:

$ systemd-loginctl list-sessions
   SESSION        UID USER             SEAT            
       c89       1000 jdebp            seat0           

1 sessions listed.

Then for each session that you are interested in show its status:

$ systemd-loginctl session-status c89
c89 - jdebp (1000)
       Since: Tue, 07 Oct 2014 20:16:20 +0100; 15s ago
      Leader: 24453 (3)
        Seat: seat0; vc6
         TTY: /dev/tty6
     Service: login; type tty; class user
      Active: yes
      CGroup: /user/jdebp/c89
          ├ 24453 login
          ├ 25661 -zsh
          └ 25866 systemd-loginctl session-status c89

The systemd people have renamed them to loginctl and logind in more recent versions.

Further reading

JdeBP
  • 68,745
  • Also: ps --no-header -eo user:32,slice,cmd|awk '$2 != "-" && ! _[$0] { _[$0]++; print }' If you're interested in kernel threads running as root, you can remove the $2 != "-" && part – Gregg Leventhal Jan 23 '21 at 16:12
2

You don't need systemd for that.

I wanted to know who is logged in since when

Use who

$ who
jimmij   tty7         2014-09-25 01:39 (:0)
jimmij   pts/0        2014-09-25 01:39 (:0)
jimmij   pts/2        2014-09-28 22:14 (:0)

or even better w to get additional information

$ w
jimmij   tty7      25Sep14 12days  4:09m  5:24  sawfish
jimmij   pts/0     25Sep14 53:43   8.81s 32:32  /usr/bin/python2.7 /usr/lib/python-exec/python2.7/ter
jimmij   pts/2     28Sep14  8days 45.08s  2.45s /bin/zsh

What are the processes currently running under his control

use ps -u user

$ ps -u jimmij
  PID TTY          TIME CMD
  352 ?        00:00:01 systemd
  353 ?        00:00:00 (sd-pam)
  359 ?        00:05:24 sawfish
  372 ?        00:00:00 dbus-launch
  373 ?        00:00:00 dbus-daemon
  375 ?        00:00:16 sawfishpager
  377 ?        00:32:32 terminator
  ...
jimmij
  • 47,140