public static void initProcess() {
        try {
            ProcessHandle currentProcess = ProcessHandle.current();
            long pid = currentProcess.pid();
            String environment = StringUtils.defaultString(System.getProperty("spring.profiles.active"), "dev");
            File pidFile = new File(CONFIG_BASE_PATH + File.separator + "config" + File.separator + environment + "app.pid");
            if (!pidFile.exists()) {
                FileUtil.writeUtf8String(String.valueOf(pid), pidFile);
            } else {
                String oldPid = FileUtil.readUtf8String(pidFile);
                log.info("oldPid:{}", oldPid);
                if (StringUtils.isNotBlank(oldPid)) {
                    Optional<ProcessHandle> processHandle = ProcessHandle.of(Long.parseLong(oldPid));
                    //log.error("processHandle:{}", JSON.toJSONString(processHandle));
                    processHandle.ifPresent(handle -> {
                        ProcessHandle.Info info = handle.info();
                        String[] arguments = info.arguments().orElse(null);
                        log.info("arguments:{}", JSON.toJSONString(arguments));
                        if (arguments == null) {
                            return;
                        }
                        for (String argument : arguments) {
                            if (StringUtils.equals("chat2db-server-start.jar", argument)) {
                                handle.destroy();
                                log.info("destroy old process--------");
                                break;
                            }
                            if (argument.contains("Application")) {
                                handle.destroy();
                                log.info("destroy old process--------");
                                break;
                            }
                        }
                    });
                }

                FileUtil.writeUtf8String(String.valueOf(pid), pidFile);
            }

        } catch (Exception e) {
            log.error("updatePid error", e);
        }

    }
Configure information on the user side

@author Jiaju Zhuang
chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/ConfigUtils.java