Konsole - which pseudo-tty per session?
I use KDE konsole; a lot. Right now my task bar shows 22 instances of konsole running, and most of those have at least 3 or 4 sessions open. Probably at least 100 in total. Most are running a secure shell session logged into another computer somewhere, and often I will have numerous separate sessions logged into any one remote host. When I list my processes with 'ps -e l', it shows me what pts the session started on, like this:
Code:
0 1142 4772 6451 16 0 4484 948 select S+ pts/25 1:45 ssh -L 8000:ibcs:8000 ibcs I can't find anything within konsole itself that seems to identify the relationship between konsole sessions, and pts's. Are there any 'hidden' places where this might be found? Hope this makes sense. --- rod. |
Where are you getting the pts ID from? Are you getting this from the host which you are sshing out of, or from the remote host?
If you're getting the pts from the local host, it's fairly easy - just send the HUP signal to the bash shell which has that pts - it will disconnect from the remote host and close the shell. You can get the process ID from the ps output which tells you the pts ID. For example, I started a bunch of konsole sessions, and used ssh in several of them to connect to a remote host. Lets say I want to disconnect the ssh connection on pts/8: Code:
$ ps aux |grep pts/8 Code:
kill -HUP 9570 If I sent the signal to the ssh process instead of the bash shell, it would disconnect, but the bash shell (and that tab in konsole) would remain open. |
Quote:
edit: You can set the title bar with: Code:
echo -n "\e]0;<TEXT>\007" Code:
TTY=$(tty) Oh, you just want to close it, missed that at first. In that case, you can just KILL/HUP the shell, as matthewg42 demonstrated. Though if you want to switch to a given konsole (not close it), the above might be useful. (re)(re)edit: If you want to simplify the output of ps, try something like: Code:
ps -U $USER -o pid,tty,comm |
Another way to name the tabs is via the dcop interface:
Code:
dcop "$KONSOLE_DCOP_SESSION" renameSession "My tab name" 1. Get a list of konsole PIDs using pgrep 2. For each konsole PID, look in /proc/<PID>/fd and find symlinks to pts devices. Now you have a list of pts's for that konsole window. 3. You've now narrowed your search down to one konsole instance, but there are still multiple tabs to work through. We can use dcop, but it's a little ugly - several calls: Code:
dcop konsole-<PID> |grep session Code:
dcop konsole-<PID> session-x sessionPID Code:
ps -p <BASH-PID> -o tty= Code:
dcop konsole-<PID> session-x sessionName |
More dcop goodness... if you know the konsole ID and the session ID, you can make konsole switch to that tab using the dcop interface. An example:
Code:
dcop konsole-9437 konsole activateSession session-7 |
Great answers, all. I haven't quite digested them all yet, but I'm pretty sure there is more than one useful solution there. What I didn't say was that I usually don't want to just drop the connection(s) ungracefully, so just killing the shell isn't usually my preferred solution, but is a solution, nonetheless. I've always wondered what dcop was good for; looks like I now have a good excuse to find out.
Thanks muchly, folks. --- rod. |
All times are GMT -5. The time now is 06:14 AM. |