Skip to content

Commit b51e53b

Browse files
committed
server : add pidfile option
So we can track the pid of this process Signed-off-by: Eric Curtin <[email protected]>
1 parent 860a9e4 commit b51e53b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

common/arg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,5 +3373,9 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
33733373
}
33743374
).set_examples({LLAMA_EXAMPLE_SERVER}));
33753375

3376+
add_opt(common_arg({ "--pidfile" }, "FILE", "path to PID file for server process",
3377+
[](common_params & params, const std::string & value) { params.pidfile = value; })
3378+
.set_examples({ LLAMA_EXAMPLE_SERVER }));
3379+
33763380
return ctx_arg;
33773381
}

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ struct common_params {
366366
std::string hostname = "127.0.0.1";
367367
std::string public_path = ""; // NOLINT
368368
std::string chat_template = ""; // NOLINT
369+
std::string pidfile = ""; // path to PID file for server process // NOLINT
369370
bool use_jinja = false; // NOLINT
370371
bool enable_chat_template = true;
371372
common_reasoning_format reasoning_format = COMMON_REASONING_FORMAT_DEEPSEEK;

tools/server/server.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3691,6 +3691,19 @@ inline void signal_handler(int signal) {
36913691
shutdown_handler(signal);
36923692
}
36933693

3694+
static int create_pidfile(const std::string & pidfile) {
3695+
FILE * f = ggml_fopen(pidfile.c_str(), "w");
3696+
if (!f) {
3697+
LOG_ERR("Unable to open PID file: %s\n", pidfile.c_str());
3698+
return -1;
3699+
}
3700+
3701+
fprintf(f, "%d\n", getpid());
3702+
fclose(f);
3703+
3704+
return 0;
3705+
}
3706+
36943707
int main(int argc, char ** argv) {
36953708
// own arguments required by this example
36963709
common_params params;
@@ -3699,6 +3712,7 @@ int main(int argc, char ** argv) {
36993712
return 1;
37003713
}
37013714

3715+
create_pidfile(params.pidfile);
37023716
common_init();
37033717

37043718
// struct that contains llama context and inference

0 commit comments

Comments
 (0)