Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #263734 > unrolled thread

Get running time of child process

Started byFranco Martelli <martellif67@gmail.com>
First post2023-11-20 21:00 +0100
Last post2023-11-22 06:40 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.debian.user


Contents

  Get running time of child process Franco Martelli <martellif67@gmail.com> - 2023-11-20 21:00 +0100
    Re: Get running time of child process Michael Kjörling <2695bd53d63c@ewoof.net> - 2023-11-20 21:30 +0100
      Re: Get running time of child process Franco Martelli <martellif67@gmail.com> - 2023-11-21 16:40 +0100
        Re: Get running time of child process Michael Kjörling <2695bd53d63c@ewoof.net> - 2023-11-21 17:50 +0100
          Re: Get running time of child process Franco Martelli <martellif67@gmail.com> - 2023-11-21 20:50 +0100
            Re: Get running time of child process <tomas@tuxteam.de> - 2023-11-22 06:40 +0100

#263734 — Get running time of child process

FromFranco Martelli <martellif67@gmail.com>
Date2023-11-20 21:00 +0100
SubjectGet running time of child process
Message-ID<HCiB3-6NSG-3@gated-at.bofh.it>
Hi,
Get running time of child process
I've Picom running on my system with these PIDs:

~$ pstree -hpan | grep picom
   |   |   |   |   `-grep,6199 picom
   |-picom,1620 -b --config /home/myuser/.config/picom.conf
   |   `-{picom},3507

If I do:

~$ ps -eo pid,lstart,etime | grep 1620
    1620 Mon Nov 20 16:12:47 2023    01:22:39

1620 is the PID of the parent process, the command returns the date when 
the parent process had started and the elapsed time as I expected. But 
if I do the same command for the its child process (PID 3507):

~$ ps -eo pid,lstart,etime | grep 3507

the command returns nothing.
So, is it possible to have the starting time and the elapsed time of a 
child process?
Thanks in advance, kind regards
-- 
Franco Martelli

[toc] | [next] | [standalone]


#263735

FromMichael Kjörling <2695bd53d63c@ewoof.net>
Date2023-11-20 21:30 +0100
Message-ID<HCj45-6Ohz-1@gated-at.bofh.it>
In reply to#263734
On 20 Nov 2023 20:55 +0100, from martellif67@gmail.com (Franco Martelli):
> ~$ ps -eo pid,lstart,etime | grep 1620
>    1620 Mon Nov 20 16:12:47 2023    01:22:39
> 
> 1620 is the PID of the parent process, the command returns the date when the
> parent process had started and the elapsed time as I expected. But if I do
> the same command for the its child process (PID 3507):
> 
> ~$ ps -eo pid,lstart,etime | grep 3507
> 
> the command returns nothing.

Try using ps -q instead of grep to get information on a specific PID:

$ ps -eo pid,lstart,etime -q 1620,3507

If that doesn't return anything for the child process, maybe it simply
has exited?

-- 
Michael Kjörling                     🔗 https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”

[toc] | [prev] | [next] | [standalone]


#263757

FromFranco Martelli <martellif67@gmail.com>
Date2023-11-21 16:40 +0100
Message-ID<HCB0Z-70XD-13@gated-at.bofh.it>
In reply to#263735
On 20/11/23 at 21:22, Michael Kjörling wrote:
> $ ps -eo pid,lstart,etime -q 1620,3507
> 
> If that doesn't return anything for the child process, maybe it simply
> has exited?

Thanks it works, but instead of the child PID it is shown the parent PID:

~$ ps -eo pid,lstart,etime -q 1620,6841
     PID                  STARTED     ELAPSED
    1620 Mon Nov 20 16:12:47 2023    23:47:16
    1620 Tue Nov 21 15:59:36 2023       00:28

for me it doesn't matter, it is obvious that the last row refers to the 
child process. Picom forks a new child when its configuration file is 
changed:

~$ touch /home/myuser/.config/picom.conf

now the new Picom's child has PID 6841, thanks again

-- 
Franco Martelli

[toc] | [prev] | [next] | [standalone]


#263758

FromMichael Kjörling <2695bd53d63c@ewoof.net>
Date2023-11-21 17:50 +0100
Message-ID<HCC6J-71zU-9@gated-at.bofh.it>
In reply to#263757
On 21 Nov 2023 16:34 +0100, from martellif67@gmail.com (Franco Martelli):
>> $ ps -eo pid,lstart,etime -q 1620,3507
> 
> Thanks it works, but instead of the child PID it is shown the parent PID:
> 
> ~$ ps -eo pid,lstart,etime -q 1620,6841
>     PID                  STARTED     ELAPSED
>    1620 Mon Nov 20 16:12:47 2023    23:47:16
>    1620 Tue Nov 21 15:59:36 2023       00:28

Maybe for that what you want is "tid" not "pid"?

-- 
Michael Kjörling                     🔗 https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”

[toc] | [prev] | [next] | [standalone]


#263759

FromFranco Martelli <martellif67@gmail.com>
Date2023-11-21 20:50 +0100
Message-ID<HCEUV-73c2-3@gated-at.bofh.it>
In reply to#263758
On 21/11/23 at 17:43, Michael Kjörling wrote:
>> ~$ ps -eo pid,lstart,etime -q 1620,6841
>>      PID                  STARTED     ELAPSED
>>     1620 Mon Nov 20 16:12:47 2023    23:47:16
>>     1620 Tue Nov 21 15:59:36 2023       00:28
> Maybe for that what you want is "tid" not "pid"?

Wonderful this did the trick:

~$ ps -eo tid,lstart,etime -q 1620,6841
     TID                  STARTED     ELAPSED
    1620 Mon Nov 20 16:12:47 2023  1-01:33:53
    6841 Tue Nov 21 15:59:36 2023    01:47:05

I guess TID means Thread IDentifier although in the "ps" man page is not 
explicitly mentioned:
...
tid         TID       the unique number representing a dispatchable 
entity (alias lwp, spid).  This value may also appear as: a process ID 
(pid); a process group ID (pgrp); a session ID for the session leader 
(sid); a thread group ID for the thread group leader (tgid); and a tty 
process group ID for the process group leader (tpgid).
...

I'm wrong? What does it mean?

-- 
Franco Martelli

[toc] | [prev] | [next] | [standalone]


#263767

From<tomas@tuxteam.de>
Date2023-11-22 06:40 +0100
Message-ID<HCO7T-79uC-1@gated-at.bofh.it>
In reply to#263759

[Multipart message — attachments visible in raw view] — view raw

On Tue, Nov 21, 2023 at 08:47:08PM +0100, Franco Martelli wrote:
> On 21/11/23 at 17:43, Michael Kjörling wrote:
> > > ~$ ps -eo pid,lstart,etime -q 1620,6841
> > >      PID                  STARTED     ELAPSED
> > >     1620 Mon Nov 20 16:12:47 2023    23:47:16
> > >     1620 Tue Nov 21 15:59:36 2023       00:28
> > Maybe for that what you want is "tid" not "pid"?
> 
> Wonderful this did the trick:
> 
> ~$ ps -eo tid,lstart,etime -q 1620,6841
>     TID                  STARTED     ELAPSED
>    1620 Mon Nov 20 16:12:47 2023  1-01:33:53
>    6841 Tue Nov 21 15:59:36 2023    01:47:05
> 
> I guess TID means Thread IDentifier although in the "ps" man page is not
> explicitly mentioned:

Basically, yes -- although "threads" (Linux light-weight processes) are
the basis of processes, threads and all other similar things). So a
process is just a "thread" with some more baggage (cf. man 2 clone).

Might be confusing if you come from other contexts where threads are
totally separated from processes. In Linux, a process is just a fat
thread.

Cheers
-- 
t

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web