Mailing List Archive

Feature Request: PID writeout on background
Hi all.

I have a simple feature request for the devs and maintainers; when
forking into the background using the -f optarg one would normally have
to consult the process table of whatever OS they're running to find the
process. Would you consider adding another optarg to write the PID out
to stdout or a pidfile? This would be rather helpful in several
usecases.

Thanks,

-c
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Feature Request: PID writeout on background [ In reply to ]
On Tue, 27 Oct 2020, chris wrote:

> Hi all.
>
> I have a simple feature request for the devs and maintainers; when
> forking into the background using the -f optarg one would normally have
> to consult the process table of whatever OS they're running to find the
> process. Would you consider adding another optarg to write the PID out
> to stdout or a pidfile? This would be rather helpful in several
> usecases.

You can retrieve this if you configure a control socket:

$ ssh -S /tmp/sock -nNf host
$ ssh -S /tmp/sock -O check host
Master running (pid=3509649)
$ ssh -S /tmp/sock -O exit host
Exit request sent.

-d
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Feature Request: PID writeout on background [ In reply to ]
On Wed, Oct 28, 2020 at 02:36:04PM +1100, Damien Miller wrote:
> On Tue, 27 Oct 2020, chris wrote:
>
> > Hi all.
> >
> > I have a simple feature request for the devs and maintainers; when
> > forking into the background using the -f optarg one would normally have
> > to consult the process table of whatever OS they're running to find the
> > process. Would you consider adding another optarg to write the PID out
> > to stdout or a pidfile? This would be rather helpful in several
> > usecases.
>
> You can retrieve this if you configure a control socket:
>
> $ ssh -S /tmp/sock -nNf host
> $ ssh -S /tmp/sock -O check host
> Master running (pid=3509649)
> $ ssh -S /tmp/sock -O exit host
> Exit request sent.
>
> -d

Well that's handy. Thanks for the heads-up!

-c
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Feature Request: PID writeout on background [ In reply to ]
On 10/28/20 5:36 AM, Damien Miller wrote:
> On Tue, 27 Oct 2020, chris wrote:
>
>> Hi all.
>>
>> I have a simple feature request for the devs and maintainers; when
>> forking into the background using the -f optarg one would normally have
>> to consult the process table of whatever OS they're running to find the
>> process. Would you consider adding another optarg to write the PID out
>> to stdout or a pidfile? This would be rather helpful in several
>> usecases.
>
> You can retrieve this if you configure a control socket:
>
> $ ssh -S /tmp/sock -nNf host
> $ ssh -S /tmp/sock -O check host
> Master running (pid=3509649)
> $ ssh -S /tmp/sock -O exit host
> Exit request sent.

There might also be a 'ControlMaster' setting hidden in ssh_config(5) in
that example. It seems to be needed to create the designated socket:

$ ssh -S /tmp/sock -Nf server.example.com; ls -lh /tmp/sock
ls: cannot access '/tmp/sock': No such file or directory

$ ssh -S /tmp/sock -MNf server.example.com; ls -lh /tmp/sock
srw------- 1 lars lars 0 Oct 28 07:29 /tmp/sock

I notice that with -f the $! variable stays blank.

/Lars
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Feature Request: PID writeout on background [ In reply to ]
On Wed, 28 Oct 2020, Lars Noodén wrote:

> I notice that with -f the $! variable stays blank.

That’s because it’s the process itself that dæmonises,
not the shell backgrounding it.

Nice trick, with the control socket; this could become
a part of the EXAMPLES section in the manpage? Also, is
the text stable and not internationalised or localised?

bye,
//mirabilos
--
„Cool, /usr/share/doc/mksh/examples/uhr.gz ist ja ein Grund,
mksh auf jedem System zu installieren.“
-- XTaran auf der OpenRheinRuhr, ganz begeistert
(EN: “[…]uhr.gz is a reason to install mksh on every system.”)
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Feature Request: PID writeout on background [ In reply to ]
On Wed, 28 Oct 2020 at 16:47, Lars Noodén <lars.nooden@gmx.com> wrote:
[...]
> I notice that with -f the $! variable stays blank.

$! is the pid of the last process placed into the background by the
shell's job control. From the shell's perspective, "ssh -f" runs in
the foreground briefly then exits (after forking a copy of itself to
run in the background, but that's not something the shell has
visibility into). Shell job control is not involved, so $! is not
set.

--
Darren Tucker (dtucker at dtucker.net)
GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860 37F4 9357 ECEF 11EA A6FA (new)
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev