Skip to content
New issue

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

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

Already on GitHub? # to your account

The time obtained by the CreateTime() method is unstable, which leads to unstable judgment results of the isRunning() method #1792

Open
1 of 5 tasks
DesistDaydream opened this issue Feb 13, 2025 · 0 comments

Comments

@DesistDaydream
Copy link

DesistDaydream commented Feb 13, 2025

Describe the bug
[A clear and concise description of what the bug is.]

The time obtained by the CreateTime() method is unstable, which leads to unstable judgment results of the isRunning() method

The result of ctime is not a fixed value

Image

To Reproduce

func isRunning(p *process.Process) (bool, error) {
	ctx := context.Background()

	createTime, err := p.CreateTimeWithContext(ctx)
	if err != nil {
		return false, err
	}

	logrus.Debugf("current process create time: %v", createTime)

	p2, err := process.NewProcessWithContext(ctx, p.Pid)
	if errors.Is(err, process.ErrorProcessNotRunning) {
		return false, nil
	}

	createTime2, err := p2.CreateTimeWithContext(ctx)
	if err != nil {
		return false, err
	}
	logrus.Debugf("new instance create time: %v", createTime2)

	return createTime == createTime2, nil
}

Expected behavior
[A clear and concise description of what you expected to happen.]

When the process is not restarted, the value of ctime should be fixed

Environment (please complete the following information):

  • Windows: [paste the result of ver]
  • Linux: [paste contents of /etc/os-release and the result of uname -a]
  • Mac OS: [paste the result of sw_vers and uname -a
  • FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
  • OpenBSD: [paste the result of uname -a]

Image

Additional context
[Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant