I enter in the raspberrypi4 server machine from the client machine using ssh and I start the server normally with $vncserver command. Then I connect to the machine using tigervncviewer, XFCE4 session or CTWM session, result is the same. When I exit XFCE4 or CTWM desktop, vncserver session continues running
That's how X servers work: unless something kills them, they continue to run. vncserver (the one in /usr/pkg/bin) has an `-autokill' switch for this.
and I must kill it with $vncserver -kill :1
That's what `-autokill' does.
I have vncserver also in a Debian GNU/Linux machine and when I exit desktop vncserver is automatically terminated. I do not understand why I get different behaviour in NetBSD.
Linux uses a different vncserver script which runs Xvnc the usual way, ie. using xinit, and xinit, as the man-page explains: When this first client exits, xinit will kill the X server and then terminate. therefore, it works on Linux. You can see this script in /usr/pkg/libexec/vncserver but, it's not usable on NetBSD without a bit of fiddling, it looks like. God knows why it's included in the package. Same for the vncsession-start script in that dir. HTH, -RVP