while working I start lots of gnome-terminals and do something with them. dd
on first terminal, 12 ssh sessions to a bunch of servers to do something. These sessions are finishing it's job and get disconnected for idle or because the session is closed after the command.
However, I need a script which closes unused gnome-terminal processes. I thought about softly killing all zsh processes without child processes. This will hopefully close the terminal in a clean way.
init─┬─[...]
├─gnome-terminal─┬─gnome-pty-helpe
│ ├─2*[zsh───ssh]
│ ├─zsh───dd
│ ├─zsh───pstree
│ ├─4*[zsh] <<<<
│ └─{gnome-terminal}
.
.
.
I thinking about writing a more or less simple bash script to check the running processes and end them if zsh has no child processes and no activity for 4 hours.
I am unsure
- If this is a good idea generally.
- If somebody already published a tool to do this
- If there is a way to get the child processes of zsh (without
grep
ing andawk
ing thepstree
output 😉 - How I get the last activity (thought about a pre and post command in zsh)
- If there is a better way than
kill -HUP <zsh pid>
to end the processes
Thanks in advance
Best Answer
According to the zsh manual
I tested
and the superior gnome-terminal died when the shell quit. The same mechanism also works within bash. This does address your concerns about nuking busy terminals, as it only starts counting after issuing a shell prompt
I don't think it a good idea generally, as it creates "magical" events which could potentially lose state. I'd recommend getting better with the "close window" and "focus another window (maybe a terminal)" keys of your window manager of choice. But if you do want poofing terminals, this is probably the best way to go.