0

Environment: CentOS 8

I turned on real time logging with the command,

$ journalctl -f &

I got the information I needed but unfortunately I'm not sure how to stop it. [CTRL] -c does not stop it.

Is there a simple command to terminate live logging?

digijay
  • 1,074
  • 3
  • 9
  • 22
myNewAccount
  • 519
  • 1
  • 5
  • 14

1 Answers1

1

You have started the journalctl process in the background (by using ampersand & at the end of the line), which means that it is executed independently of the shell from where you started it. Thus you can't stop the process by hitting CTRL+c.

To stop all journalctl processes at once you could just enter

killall journalctl

This will stop all processes named journalctl that have been started with your system user.

If you are unsure if there are more processes with that name you could check this with grepping the process list for journalctl:

ps fax | grep journalctl

This will give you an output like this:

ps fax | grep journalctl
 2367 pts/7    S      0:00          |       \_ journalctl -f
 2371 pts/7    S+     0:00          |       \_ grep --color=auto journalctl

In this example the first entry would be the journalctl process, the second results from grepping the process list (which greps itself). The first column of the output shows the process id (pid). In order to stop one specific journalctl process just enter

kill 2367

Mind that you will have to have adequate permissions to stop that process. This means that if the process has been startet by a root user then you can only stop the process if your user also has root privilege, e.g. using sudo to execute the killall or kill command.

digijay
  • 1,074
  • 3
  • 9
  • 22
  • 1
    It might worth mentioning that until you exit the shell which started the `journalctl` process, you can query the background processes with the `jobs` command, and use `kill %jobid` to kill a specific background job. – Lacek May 28 '20 at 10:42
  • @Lacek yes (and also `fg` and `bg`), provided you have these tools installed on your system (which is not default) – digijay May 28 '20 at 11:35
  • `jobs`, `fg`, and `bg` are bash builtins, not separate tools. – Lacek May 29 '20 at 08:32