[lxc-users] Strange handling of background processes by lxc-attach

Marat Khalili mkh at rqc.ru
Thu Jun 1 08:41:06 UTC 2017


Dear all,

I tried starting background processes with lxc-attach and found strange 
behaviour in Ubuntu Xenial (both container and host).

When I start lxc-attach without command and type my command in shell, it 
waits for background process to end before completing the exit:

> root at host:~# lxc-attach -n test
> root at test:~# sleep 10 &
> [1] 14607
> root at test:~# exit
# hangs here for 10 seconds
> root at host:~#

When I do it with nohup it works as indended: no wait, process continues 
in the background:

> root at host:~# lxc-attach -n test
> root at test:~# nohup sleep 10 &
> [1] 14621
> nohup: ignoring input and appending output to 'nohup.out'
> root at test:~# exit
> root at host:~# lxc-attach -n test -- pgrep sleep
> 14621
> root at host:~#

When I specify command in lxc-attach arguments or pass it 
non-interactively, background process gets killed, even with nohup! (I 
wonder what signal it gets.) There're no hangs below:

> root at host:~# lxc-attach -n test -- bash -c 'nohup sleep 10 &'
> root at host:~# echo 'nohup sleep 10 &' | lxc-attach -n test
> root at host:~# lxc-attach -n test -- pgrep sleep
> root at host:~# 

Finally, nohup bash works:

> root at host:~# lxc-attach -n test -- nohup bash -c 'sleep 10 &'
> nohup: appending output to 'nohup.out'
> root at host:~# echo 'sleep 10 &' | lxc-attach -n test -- nohup bash
> nohup: ignoring input and appending output to 'nohup.out'
> root at host:~# lxc-attach -n test -- pgrep sleep
> 14732
> 14734
> root at host:~#

I wonder if this is intended or should be reported as a bug? I guess 
this is somehow related to missing parent, right?


> root at host:~# uname -a
> Linux host 4.4.0-78-generic #99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 
> 2017 x86_64 x86_64 x86_64 GNU/Linux
>
> root at host:~# lsb_release -a
> No LSB modules are available.
> Distributor ID:    Ubuntu
> Description:    Ubuntu 16.04.2 LTS
> Release:    16.04
> Codename:    xenial


--

With Best Regards,
Marat Khalili


More information about the lxc-users mailing list