0

I am doing ps -ef | grep process.

I am getting an output in this format:

17297     1 12 Jan10 ?        02:53:26 /usr/java/jdk1.8.0_221-amd64/bin/java

Here instead of Jan10, I want Jan10 2021

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
  • 1
    Does this answer your question? [How to get the start time of a long-running Linux process?](https://stackoverflow.com/questions/5731234/how-to-get-the-start-time-of-a-long-running-linux-process) – Marged Jan 11 '21 at 12:27
  • You may be able to use the birth date of /proc/17297/stat and so stat --printf "%w" /proc/17297/stat – Raman Sailopal Jan 11 '21 at 13:05

1 Answers1

1

Use the formatted output (-o option) of ps command and choose the format. For example:

$ ps -eo pid,ppid,lstart,cmd
    PID    PPID                  STARTED COMMAND
      1       0 Mon Jan 11 12:26:03 2021 systemd
      2       0 Mon Jan 11 12:26:03 2021 kthreadd
      3       2 Mon Jan 11 12:26:03 2021 rcu_gp
      4       2 Mon Jan 11 12:26:03 2021 rcu_par_gp
      5       2 Mon Jan 11 12:26:03 2021 kworker/0:0-events
      6       2 Mon Jan 11 12:26:03 2021 kworker/0:0H-kblockd
      9       2 Mon Jan 11 12:26:03 2021 mm_percpu_wq
[...]

Available formats are described in the "STANDARD FORMAT SPECIFIERS" section of the manual.

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
  • Thanks for sharing. If I am using ps -eo pid,lstart it is listing down all the processes. I want only one particular process which I am fetching from some name like this ps -ef | grep Java. Can you help how can I fetch this process only in the format Month day year for the start process – Shubham Dhote Jan 11 '21 at 12:44
  • You do it using a pipe as you showed in your question : ps -eo pid,ppid,lstart,cmd | grep Java – Rachid K. Jan 11 '21 at 12:52
  • I tried this ps -eo pid,lstart | grep Java but it is not showing anything, where as when I do ps -ef | grep Java it does show the output 17297 1 12 Jan10 ? 02:56:14 /usr/java/jdk1.8.0_221-amd64/bin/java But I want:- 17297 1 12 Jan10 2021? 02:56:14 /usr/java/jdk1.8.0_221-amd64/bin/java like this in the format. The year should also append. – Shubham Dhote Jan 11 '21 at 12:57
  • You need the complete command line ? Use the "args" format for example: ps -eo pid,ppid,lstart,args – Rachid K. Jan 11 '21 at 13:13