Skip to content

server : add pidfile option #14242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

server : add pidfile option #14242

wants to merge 1 commit into from

Conversation

ericcurtin
Copy link
Collaborator

So we can track the pid of this process

@ericcurtin ericcurtin requested a review from ngxson as a code owner June 17, 2025 13:24
@ericcurtin ericcurtin requested review from Copilot and ggerganov and removed request for Copilot June 17, 2025 13:24
Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a PID file option for the server process so that the process ID can be tracked.

  • Implements a new PidFile class in tools/server/server.cpp to handle creation, management, and cleanup of a PID file.
  • Adds a new command-line option "--pidfile" to set the PID file path (common/arg.cpp and common/common.h).

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tools/server/server.cpp Introduces PidFile class and PID file lifecycle management.
common/common.h Adds a new pidfile field to common_params.
common/arg.cpp Adds a new command-line argument for configuring the pidfile.
Comments suppressed due to low confidence (1)

tools/server/server.cpp:3780

  • [nitpick] Consider renaming the variable 'f' to a more descriptive name such as 'pidFileHandler' to improve code clarity.
    PidFile f;

@ericcurtin
Copy link
Collaborator Author

@ngxson @ggerganov might be worth another look, it's more advanced now

Comment on lines +3780 to +3783
PidFile f;
if (!params.pidfile.empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variable is not used outside its scope, so it's better to move inside the if {..}

Suggested change
PidFile f;
if (!params.pidfile.empty()) {
if (!params.pidfile.empty()) {
PidFile f;

Copy link
Collaborator Author

@ericcurtin ericcurtin Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there's a reason it's in the outer scope, we want the destructor to attempt to delete the file when main() exits, not any sooner

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok maybe put this as a comment for visibility

}
};

static bool is_old_pid_alive(const std::string & filename) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move all static function into the class PidFile

return false; // Process does not exist or other error
}

class PidFile {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move it to utils.hpp to avoid pollute server.cpp with non-server code

bool rm = false;

FILE * open(const std::string & filename, const char * mode, const bool r = false) {
file = ggml_fopen(filename.c_str(), mode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already had many functions to handle file i/o in common.cpp, should reuse it instead of inventing a new one

@ericcurtin ericcurtin force-pushed the add-pidfile branch 2 times, most recently from 7e9ce12 to 57507f3 Compare June 17, 2025 17:15
So we can track the pid of this process

Signed-off-by: Eric Curtin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants