From 9e2590eb15f599d3818e5a5f2602965704fd9a3b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 7 Aug 2021 16:45:12 +0530 Subject: [PATCH] Set the KITTY_PID env var when running child processes --- docs/glossary.rst | 7 +++++++ kitty/child.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/glossary.rst b/docs/glossary.rst index ce955bc89..fb96089e9 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -78,6 +78,13 @@ Variables that kitty sets when running child programs Can be used with the :doc:`kitty remote control facility `. +.. envvar:: KITTY_PID + + An integer that is the process id for the kitty process in which the program + is running. Allows programs to tell kitty to reload its config by sending it + the SIGUSR1 signal. + + .. envvar:: WINDOWID The id for the :term:`OS Window ` the program is running in. Only available diff --git a/kitty/child.py b/kitty/child.py index 785d7c7c5..8f1f59ede 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -14,6 +14,7 @@ import kitty.fast_data_types as fast_data_types from .constants import is_macos, shell_path, terminfo_dir +from .types import run_once try: from typing import TypedDict @@ -23,8 +24,9 @@ if is_macos: from kitty.fast_data_types import ( - cmdline_of_process, cwd_of_process as _cwd, environ_of_process as _environ_of_process, - process_group_map as _process_group_map + cmdline_of_process, cwd_of_process as _cwd, + environ_of_process as _environ_of_process, + process_group_map as _process_group_map ) def cwd_of_process(pid: int) -> str: @@ -170,6 +172,11 @@ def openpty() -> Tuple[int, int]: return master, slave +@run_once +def getpid() -> str: + return str(os.getpid()) + + class ProcessDesc(TypedDict): cwd: Optional[str] pid: int @@ -216,6 +223,7 @@ def final_env(self) -> Dict[str, str]: env.update(self.env) env['TERM'] = fast_data_types.get_options().term env['COLORTERM'] = 'truecolor' + env['KITTY_PID'] = getpid() if self.cwd: # needed in case cwd is a symlink, in which case shells # can use it to display the current directory name rather