Methods of payment Abuse

Switching to another session and terminating processes in loginctl

09.12.2022, 16:30

We have looked at the syntax and other important features of the loginctl program, now let's talk about how to switch between sessions and terminate processes. It is very easy to do this and you don't need to have any specific knowledge. Next we will tell you how to put it all into practice.

Changing a session by switching

How to switch to another session? You can use the GUI for this purpose. But if you do not want to use the terminal, then solve the task with the help of a utility.

To do this, all you need to do is execute:

$ loginctl activate 3

The command allows you to switch a session with an identifier. In the same way, you can switch back as well. Even more convenience in switching is provided by TTY due to hotkeys. After switching, you can immediately perform a screen lock.

Execute session-lock:

$ loginctl session-lock 1

Next, let's tell you the instruction to terminate a particular user process.

Ending a session and process

Let's move on to the next issue - terminating active processes and specific sessions. With kill-useror kill-session, you can terminate processes running as a user or only a specific session. These two commands work exactly the same way as the kill console utility, hence they can be used to terminate a process as well as send a specific signal.

When kill-session simply terminates the session:

$ loginctl kill-session 3

The user can also use the --signal option to send any other signal. It is set so that the SIGTERM signal is always sent.

To perform a SIGKILL transmission, execute:

$ loginctl kill-session 3 --signal SIGKILL

There is also a command that allows you to terminate all active processes of a single user - kill-user. You can also use session-terminate. It solves the same problem and also gives you the right to select a signal and terminate the process at the same time:

$ loginctl terminate-session 3

Now you know even more about loginctl.