Let's say you have a bash terminal open, in which you have typed a lot of commands, many of which are probably not yet saved in $HISTFILE. Additionally, let's say that you have a long running command running in that terminal, so you can't really stop this command to issue history -a to append new entries to/flush to the $HISTFILE.

My question is: is it possible to trigger the equivalent of history -a, in a bash shell which has a process running inside it, remotely - that is, just by knowing this shell's PID? Maybe there's some sort of signal that can be issued to the running bash process - but could I issue that via bash or standard tools?

(I'm trying to develop a Python psutil script which will save settings of all my open bash terminals and their history files, and for this to make sense, I guess all these bash processes need to flush their unflushed lines to respective $HISTFILEs, before the script copies these files; and some of these shells may have long-running processes in them. So if this "remote history flush" is doable from another bash instance, then it will be doable via Python too...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.