Re: OpenBSD 7.3 found a process with PID 0

2023-09-27 Thread Claudio Jeker
On Tue, Sep 26, 2023 at 06:12:20PM +0200, Alessandro Baggi wrote:
> 
> 
> Il 26/09/23 17:30, Claudio Jeker ha scritto:
> > On Tue, Sep 26, 2023 at 05:13:46PM +0200, Andreas Kähäri wrote:
> > > On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:
> > > > Hi list,
> > > > running this python3 script:
> > > > 
> > > > #!/usr/bin/env python3
> > > > import psutil
> > > > 
> > > > pids = psutil.pids()
> > > > for i in pids:
> > > >  p = psutil.Process(i)
> > > >  with p.oneshot():
> > > >  print(str(i) + " " + p.name())
> > > > 
> > > > The result start with:
> > > > 
> > > > 0 swapper
> > > > 1 init
> > > > 536 smtpd
> > > > 868 ksh
> > > > ...
> > > > 
> > > > This process does not appear in ps, top and htop.
> > > 
> > > $ ps -p 0
> > >PID TT  STATTIME COMMAND
> > >0 ??  DK   0:02.19 (swapper)
> > > 
> > > For top, you need to press S to show system processes.  I don't use
> > > htop, but I assume it has a similar capability to show system processes.
> > > 
> > > > 
> > > > How could be that there is a process with PID 0 before init?
> > > > Probably I'm missing something about OpenBSD core.
> > > > 
> > > > Can someone point me in the right direction?
> > > > 
> > > 
> > > See uvm_init(9):
> > > 
> > >   The swapper process swaps in runnable processes that are
> > >   currently swapped out, if there is room.
> > > 
> > 
> > ... and this is a lie. The swapper process does nothing.
> > 
> 
> Ok, but why it is running?

Because it is the main() thread and nobody cleaned up that mess.

-- 
:wq Claudio



Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Janne Johansson
>
> How could be that there is a process with PID 0 before init?
> Probably I'm missing something about OpenBSD core.
>

As for this small part of the mystery, even init starts out as a skeleton
process created early by the kernel, which then does an exec() of
/sbin/init so that whatever program lies there on disk replaces the
skeleton and retains its pid. When you know that part, it would not be
unimaginable to have the kernel create another process (the swapper in this
case) even before that happens.

After init-from-disk runs, all other processes must in some way be a
descendant of it, but that "rule" does not cover the first two pids at
least, which you can later see are the only ones without randomized pids.

For the rest of your questions, others have chipped in already.

-- 
May the most significant bit of your life be positive.


Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Benjamin Stürz

Am 26.09.23 um 18:12 schrieb Alessandro Baggi:



Il 26/09/23 17:30, Claudio Jeker ha scritto:

On Tue, Sep 26, 2023 at 05:13:46PM +0200, Andreas Kähäri wrote:

On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:

Hi list,
running this python3 script:

#!/usr/bin/env python3
import psutil

pids = psutil.pids()
for i in pids:
 p = psutil.Process(i)
 with p.oneshot():
 print(str(i) + " " + p.name())

The result start with:

0 swapper
1 init
536 smtpd
868 ksh
...

This process does not appear in ps, top and htop.


$ ps -p 0
   PID TT  STAT    TIME COMMAND
   0 ??  DK   0:02.19 (swapper)

For top, you need to press S to show system processes.  I don't use
htop, but I assume it has a similar capability to show system processes.



How could be that there is a process with PID 0 before init?
Probably I'm missing something about OpenBSD core.

Can someone point me in the right direction?



See uvm_init(9):

  The swapper process swaps in runnable processes that are
  currently swapped out, if there is room.



... and this is a lie. The swapper process does nothing.



Ok, but why it is running?


My guess without looking at the code is that it's an "idle" process,
it runs if there is nothing else to run and maybe does something like:

loop:
hlt ; wait for interrupt
jmp loop

It would make sense, but please correct me if I'm wrong.



Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Alessandro Baggi




Il 26/09/23 17:30, Claudio Jeker ha scritto:

On Tue, Sep 26, 2023 at 05:13:46PM +0200, Andreas Kähäri wrote:

On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:

Hi list,
running this python3 script:

#!/usr/bin/env python3
import psutil

pids = psutil.pids()
for i in pids:
 p = psutil.Process(i)
 with p.oneshot():
 print(str(i) + " " + p.name())

The result start with:

0 swapper
1 init
536 smtpd
868 ksh
...

This process does not appear in ps, top and htop.


$ ps -p 0
   PID TT  STATTIME COMMAND
   0 ??  DK   0:02.19 (swapper)

For top, you need to press S to show system processes.  I don't use
htop, but I assume it has a similar capability to show system processes.



How could be that there is a process with PID 0 before init?
Probably I'm missing something about OpenBSD core.

Can someone point me in the right direction?



See uvm_init(9):

  The swapper process swaps in runnable processes that are
  currently swapped out, if there is room.



... and this is a lie. The swapper process does nothing.



Ok, but why it is running?



Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Claudio Jeker
On Tue, Sep 26, 2023 at 05:13:46PM +0200, Andreas Kähäri wrote:
> On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:
> > Hi list,
> > running this python3 script:
> > 
> > #!/usr/bin/env python3
> > import psutil
> > 
> > pids = psutil.pids()
> > for i in pids:
> > p = psutil.Process(i)
> > with p.oneshot():
> > print(str(i) + " " + p.name())
> > 
> > The result start with:
> > 
> > 0 swapper
> > 1 init
> > 536 smtpd
> > 868 ksh
> > ...
> > 
> > This process does not appear in ps, top and htop.
> 
> $ ps -p 0
>   PID TT  STATTIME COMMAND
>   0 ??  DK   0:02.19 (swapper)
> 
> For top, you need to press S to show system processes.  I don't use
> htop, but I assume it has a similar capability to show system processes.
> 
> > 
> > How could be that there is a process with PID 0 before init?
> > Probably I'm missing something about OpenBSD core.
> > 
> > Can someone point me in the right direction?
> > 
> 
> See uvm_init(9):
> 
>  The swapper process swaps in runnable processes that are
>  currently swapped out, if there is room.
> 

... and this is a lie. The swapper process does nothing.

-- 
:wq Claudio



Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Alessandro Baggi

Il 26/09/23 17:13, Andreas Kähäri ha scritto:

On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:

Hi list,
running this python3 script:

#!/usr/bin/env python3
import psutil

pids = psutil.pids()
for i in pids:
 p = psutil.Process(i)
 with p.oneshot():
 print(str(i) + " " + p.name())

The result start with:

0 swapper
1 init
536 smtpd
868 ksh
...

This process does not appear in ps, top and htop.


$ ps -p 0
   PID TT  STATTIME COMMAND
   0 ??  DK   0:02.19 (swapper)

For top, you need to press S to show system processes.  I don't use
htop, but I assume it has a similar capability to show system processes.



Thank you for your suggestion.

This processes are real processes, why they are not reported as standard 
process?


Why python3 psutil() does report only the swapper process and not the 
other? This is a bug of psutil?





How could be that there is a process with PID 0 before init?
Probably I'm missing something about OpenBSD core.

Can someone point me in the right direction?



See uvm_init(9):

  The swapper process swaps in runnable processes that are
  currently swapped out, if there is room.



Thank you in advance.

Alessandro.






Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Andreas Kähäri
On Tue, Sep 26, 2023 at 04:59:22PM +0200, Alessandro Baggi wrote:
> Hi list,
> running this python3 script:
> 
> #!/usr/bin/env python3
> import psutil
> 
> pids = psutil.pids()
> for i in pids:
> p = psutil.Process(i)
> with p.oneshot():
> print(str(i) + " " + p.name())
> 
> The result start with:
> 
> 0 swapper
> 1 init
> 536 smtpd
> 868 ksh
> ...
> 
> This process does not appear in ps, top and htop.

$ ps -p 0
  PID TT  STATTIME COMMAND
  0 ??  DK   0:02.19 (swapper)

For top, you need to press S to show system processes.  I don't use
htop, but I assume it has a similar capability to show system processes.

> 
> How could be that there is a process with PID 0 before init?
> Probably I'm missing something about OpenBSD core.
> 
> Can someone point me in the right direction?
> 

See uvm_init(9):

 The swapper process swaps in runnable processes that are
 currently swapped out, if there is room.


> Thank you in advance.
> 
> Alessandro.

-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.



Re: OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Dave Voutila


Alessandro Baggi  writes:

> Hi list,
> running this python3 script:
>
> #!/usr/bin/env python3
> import psutil
>
> pids = psutil.pids()
> for i in pids:
> p = psutil.Process(i)
> with p.oneshot():
> print(str(i) + " " + p.name())
>
> The result start with:
>
> 0 swapper
> 1 init
> 536 smtpd
> 868 ksh
> ...
>
> This process does not appear in ps, top and htop.

You need to display kernel threads.

$ ps -p 0 -H
  PID TID TT  STATTIME COMMAND
0  10 ??  DK   0:01.04 (swapper)

>
> How could be that there is a process with PID 0 before init?
> Probably I'm missing something about OpenBSD core.
>
> Can someone point me in the right direction?
>
> Thank you in advance.
>
> Alessandro.



OpenBSD 7.3 found a process with PID 0

2023-09-26 Thread Alessandro Baggi

Hi list,
running this python3 script:

#!/usr/bin/env python3
import psutil

pids = psutil.pids()
for i in pids:
p = psutil.Process(i)
with p.oneshot():
print(str(i) + " " + p.name())

The result start with:

0 swapper
1 init
536 smtpd
868 ksh
...

This process does not appear in ps, top and htop.

How could be that there is a process with PID 0 before init?
Probably I'm missing something about OpenBSD core.

Can someone point me in the right direction?

Thank you in advance.

Alessandro.