Killing F8 from F7 - Bash Terminal

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Danix803
Level 1
Level 1
Posts: 4
Joined: Tue May 17, 2016 3:03 am

Killing F8 from F7 - Bash Terminal

Postby Danix803 » Wed Nov 08, 2017 7:22 pm

I log into my desktop and after a while it goes black and won't come back. I hit ctrl-alt-F1 and get a terminal. Then, I go to ctrl-alt-F7, get a terminal, log in, and type startx. KDE starts. This is all great and everything. But, how do I kill the other virtual session/instance/or whatever it's called that I'm logged into. I know that it's still there and working because whenever I try to start firefox it says that there is another instance already running.

Any help would be greatly appreciated. BTW, the advice can tell me how to do it with the gui or command line. I'm not picky. Thanks in advance. :D

User avatar
WharfRat
Level 19
Level 19
Posts: 9968
Joined: Thu Apr 07, 2011 8:15 pm

Re: Killing F8 from F7 - Bash Terminal

Postby WharfRat » Wed Nov 08, 2017 11:26 pm

Your session going black and having to restart x seems like your bigger problem, but in any event to check if FF is still active use pgrep firefox in the terminal.

If it returns a pid like this

Code: Select all

[bill@XPS] ~/script $ pgrep fire
6781
[bill@XPS] ~/script $ pgrep firefox

then you can use sudo kill -9 $(pgrep firefox) to clear it.
Image ImageImage

Danix803
Level 1
Level 1
Posts: 4
Joined: Tue May 17, 2016 3:03 am

Re: Killing F8 from F7 - Bash Terminal

Postby Danix803 » Thu Nov 09, 2017 7:34 am

Thanks for the quick response. You are the bomb.
However, I'm not trying to kill firefox. There are several ways that I could that. Use the wonderful, beautiful GUI (ctrl-esc); or the even more wonderful, beautiful command line/konsole/bash terminal/whatever (tops and pkill).
I'm not kidding though. I really do appreciate the quick response and helpful reply. But, I'm trying to kill that entire virtual session.
So, if I use sudo pkill -u username. Then, it kills username and that's what I'm signed in as. It's just a home computer. It has one account, mine.
So, if I'm logged in on F1-F6 virtual terminals (vt - that's what I'm calling 'em), and F7-F8 the GUI ones all at the same time. Is there a way to close/logoff/whatever each of those other vt's individually or in groups from just one vt???

It's not your fault about the response. It's mine. I'm probably not asking the question correctly or don't know enough about what everythings called to ask the question correctly.

Thanks again... I really do appreciate your quick and very constructive answer. :D :) :D

User avatar
Termy
Level 3
Level 3
Posts: 155
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Killing F8 from F7 - Bash Terminal

Postby Termy » Thu Nov 09, 2017 10:04 am

You don't need sudo to kill, at least normally, (I do, but I use some restrictive kernel parameters) and you might also find this useful: pkill firefox You can specify which signal to send, by using the same syntax as the usual kill commands, for example: pkill -HUP firefox As usual, you can use the integer or the name.

You can run kill -l, /bin/kill -l, killall -l, trap -l, skill -l, and various other commands to list the available signals.

But, you don't just want to kill Firefox. It looks like you want to kill everything on a given TTY. You could try the following. It sends the HUP (1) signal to processes running on TTY7. You could wrap it into a function, which could then be tied to keyboard shortcuts to kill, say, everything on TTY1, TTY2, TTY3, etc, based on the number you press on the keyboard. I would, for example, use Ctrl + Super + Alt + NUM, where NUM is the number on the keyboard for whichever TTY I wish to kill.

WARNING: Do not run this potentially inconvenient command! ...unless you know what you're doing. :lol:

Code: Select all

/usr/bin/sudo /bin/sh -c 'kill -HUP `/bin/ps -o pid= -t /dev/tty7`'

By the way, I actually do this quite often, that is, I kill what's on a TTY, usually because X messed up or something. I usually just run pkill -u $USER, as you mentioned above. It kills what's on the other TTYs, as it logs you out on there, as I've observed, but doesn't log me out of the one I'm currently in, unless I ran it again; could it be that, that is what you're after?

Just know that programs can be and often are written to handle signals. For example, a program can ignore the HUP signal, or do some clean-up before closing down; this is why it's good not to use -KILL (9) because it's "going nuclear", as they say. Linux, as a safety precaution, will or at least should always heed the KILL signal, but it's the point of no return, AFAIK.
Last edited by Termy on Sun Nov 12, 2017 8:01 pm, edited 1 time in total.
Here to help.

User avatar
Flemur
Level 13
Level 13
Posts: 4565
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Killing F8 from F7 - Bash Terminal

Postby Flemur » Thu Nov 09, 2017 11:19 am

Termy wrote:pkill -HUP firefox

I haven't been able to kill any processes "nicely", IOW, so they think they exited normally, like Program->File->Exit.

Using pkill -HUP firefox it restarts in recovery with open tabs to reload, just like "kill -9 ...", or tripping over the computer's power cord and pulling it out.
Mint 18.2 Xfce/fluxbox/pulse-less - Xubuntu 16.10/fluxbox/pulse-less
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?

User avatar
WharfRat
Level 19
Level 19
Posts: 9968
Joined: Thu Apr 07, 2011 8:15 pm

Re: Killing F8 from F7 - Bash Terminal

Postby WharfRat » Thu Nov 09, 2017 11:40 am

Well another embarrassing moment for me :oops:

You should be able to kill the VT from your logged in desktop session in the following manner as in this example:

I logged into tty1 with ctl-alt-F1 and when I pgrep login from the desktop session I get

Code: Select all

[bill@XPS] ~ $ pgrep -a login
1027 /lib/systemd/systemd-logind
2628 /bin/login --     
[bill@XPS] ~ $


The first is the the initial login to the desktop session and the second is tty1 so I want the newer one so I use pgrep -n login which returns

Code: Select all

[bill@XPS] ~ $ pgrep -n login
2628
[bill@XPS] ~ $


So I can then use sudo kill -9 $(pgrep -n login) to end that session.

I think this is what you're looking for :?
Image ImageImage

Danix803
Level 1
Level 1
Posts: 4
Joined: Tue May 17, 2016 3:03 am

Re: Killing F8 from F7 - Bash Terminal

Postby Danix803 » Thu Nov 09, 2017 9:01 pm

That is exactly what I'm looking for...
Thanks, thanks, thanks, thanks, thanks, thanks... I can't thank you all enough... :lol:
Sincerely, Thank you...

User avatar
Termy
Level 3
Level 3
Posts: 155
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Killing F8 from F7 - Bash Terminal

Postby Termy » Sun Nov 12, 2017 8:03 pm

Flemur wrote:
Termy wrote:pkill -HUP firefox

I haven't been able to kill any processes "nicely", IOW, so they think they exited normally, like Program->File->Exit.

Using pkill -HUP firefox it restarts in recovery with open tabs to reload, just like "kill -9 ...", or tripping over the computer's power cord and pulling it out.


Strange. I just ran the exact same thing on my Firefox and it loaded back up perfectly as normal. :? You could try SIGINT, for the interrupt signal which gets sent if, say, you press Ctrl + C at the terminal. Using "pkill from procps-ng 3.3.10" and "Mozilla Firefox 56.0".

Oh, oops, I see you got it sorted. :D Awesome. And I learned something new too.
Here to help.


Return to “Newbie Questions”