Bug 192573 - Add ps(1) option: Print process start time in seconds since 1970
Summary: Add ps(1) option: Print process start time in seconds since 1970
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: easy, feature, needs-qa
Depends on:
Blocks:
 
Reported: 2014-08-11 08:11 UTC by Dave Eddy
Modified: 2025-02-28 22:50 UTC (History)
2 users (show)

See Also:


Attachments
code patch for ps(1) (2.04 KB, patch)
2014-08-11 08:11 UTC, Dave Eddy
no flags Details | Diff
code patch for ps(1) (2.13 KB, patch)
2025-02-28 22:50 UTC, Mark Linimon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Eddy 2014-08-11 08:11:37 UTC
Created attachment 145651 [details]
code patch for ps(1)

This patch adds a field (sstart) to ps(1) to print the time, in seconds since January 1st 1970, when a process started.

On Solaris (and the same works on Linux I believe), you can stat(2) /proc/<pid> and inspect the mtime of the directory to determine this information, however on BSD (1) /proc doesn't set the mtime on these directories and (2) /proc is most-likely going to be removed in future releases.

Examples:

Simple example useful for scripting

$ ./ps -p $$ -o sstart=
1407708424

All "started" fields currently available for the current process

$ ./ps -p $$ -o start,lstart,sstart
STARTED STARTED                  STARTED
10:07PM Sun Aug 10 22:07:04 2014 1407708424

`sstart` is the most convenient for scripting purposes.
Comment 1 Piotr Pawel Stefaniak freebsd_committer freebsd_triage 2020-06-21 06:38:29 UTC
I think that for scripting "etimes" is probably sufficient.
Comment 2 Kubilay Kocak freebsd_committer freebsd_triage 2020-06-21 08:55:43 UTC
^Triage: 

- [tags] in issue Titles are deprecated
- Does the patch still apply to current?

@Piotr Is this a Close -> Not Accepted, or can the proposal be improved/changed?
Comment 3 Piotr Pawel Stefaniak freebsd_committer freebsd_triage 2020-06-21 09:14:46 UTC
(In reply to Kubilay Kocak from comment #2)
My comment is meant as a "I would reject this but definitely not unilaterally".
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2024-10-03 06:57:26 UTC
^Triage: clear stale flags.

To submitter: is this aging PR still relevant?
Comment 5 Dave Eddy 2024-10-05 17:02:45 UTC
(In reply to Mark Linimon from comment #4)

hello! happy 10 years since i wrote this patch - i had long since forgotten about this!

I wrote this patch originally because of the company I was working for at the time - we were transitioning to FreeBSD and my job was largely to port our software and get it working on FreeBSD.  We had some tooling that showed our services running (and their PIDs) and it was helpful to see how long ago a process was started and how long it was running.  Like I mentioned originally, on other operating systems we could just stat(2) /proc/<pid> but that didn't work for us on FreeBSD.  When I looked into it more I saw that it probably made more sense for this logic to be in the tooling (like `ps`) instead of the `/proc` filesystem - so this patch was born.

Looking at the comments on this patch I looked up "etimes" with `ps` and I agree that it would be sufficient to accomplish what I originally wanted.

I, personally, don't have much use for this patch anymore - but I will leave it up to others to see if this is something they want to include.

Thanks!
dave
Comment 6 Mark Linimon freebsd_committer freebsd_triage 2025-02-28 22:50:51 UTC
Created attachment 258126 [details]
code patch for ps(1)

^Triage: rebase patch.