Sending a command to all running ksh processes?

15 views
Skip to first unread message

Jeffery Small

unread,
Feb 22, 2023, 10:42:30 PM2/22/23
to Korn Shell
Here is a strange question.  I'm running Xubuntu 22.04.1.  I typically have 8-dual screen desktops with up to 24 separate xfce4-terminals running ksh.  Sometimes I will do something that affects all shells, such as modifying the .~/aliases file.  In this case, I have a script that I run in each window to force the shell to reread all the initialization files and perform some other basic functions.  It would be a real time saver if I could run one command and have all shells update at once.  I strongly suspect that there is no way to do something like this, but I thought I'd ask as I've learned new surprising tricks in the past.

Regards.

Martijn Dekker

unread,
Jun 6, 2023, 6:57:30 PM6/6/23
to Korn Shell
Op 23-02-2023 om 03:42 schreef Jeffery Small:
You could trap a signal for that, e.g. SIGUSR1 or SIGUSR2 which are
meant to have a user-defined purpose.

In general, to reinitialise the shell, you can do:

exec -a-ksh ksh

which will replace ksh by itself with a $0 of '-ksh'; the initial -
makes it act like a login shell. (Use a simple 'exec ksh' if that is not
wanted.) This assumes the ksh you're running is the default ksh in
$PATH. Adjust the command as necessary.

To reinitialise the shell upon receiving SIGUSR1, add this to ~/.kshrc:

trap 'exec -a-ksh ksh' USR1

Then to reinitialise all your shells on the same machine, run:

killall -USR1 ksh

Note: that command will terminate ksh sessions that do not have this
trap set.

To do this on a remote machine, run the killall command remotely via ssh.

Hope this helps (even though this response comes months later).

--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh

Reply all
Reply to author
Forward
0 new messages