This doesn't start a background process:
:!sleep 60
> Vim is not trying to parse the shell command to
> find the "&", since shell syntax is too complicated,
Vim shouldn't parse anything.
If the user wants a background process, he can type the command to
start a background process. If he doesn't, he doesn't.
> thus we use setsid() always.
But we don't use setsid() always.
This doesn't use setsid():
vim -c ':!sleep 60&'
Neither does this:
vim -g -c 'set noshelltemp' -c ':!sleep 60&'
Neither does this:
vim -g -c ':call system("sleep 60&")'
This doesn't work (apparently because of TIOCSCTTY):
vim -g -c 'set shelltemp' -c ':!sleep 60&'
And only *this* sets the setsid:
vim -g -c 'set shelltemp' -c ':!sleep 60'
If setsid was really needed all the commands above would have a
problem, but they don't.
> And if we would not use setsid() then killing Vim
> would also kill the process that was started from Vim.
No it wouldn't. Killing a parent doesn't kill the children.
Try running this program and then kill it.
#include <unistd.h>
int main(void)
{
char *const argv[] = { "/usr/bin/sleep", "60", NULL };
if (fork() == 0)
return execvp(argv[0], argv);
else
return pause();
}
The sleep process will remain there.
> > I can do an investigation of what's going on and why it might have
> > been desirable in 1996 to do setsid(). But to blankly state that it
> > probably breaks something is an assumption. We don't know that. It's
> > possible it simply was copied from somewhere because somebody else did
> > it for some reason.
> >
> > Either way that's a separate topic.
>
> Ideally everything is perfectly documented, commented, tested, etc.
> The reality is that we often don't have the time, and we just fix a
> problem and move on. Otherwise we would have perfectly written code
> with only 10% of the features we have now.
Code that doesn't get cleaned up eventually gets rewritten.
Everything needs to get cleaned up eventually.
Cheers.
--
Felipe Contreras