On my system, yes doesn't react to SIGTSTP, which is the signal sent by stop-process (rather than SIGSTOP as one might assume).
When you run yes in your terminal and shell, C-z is going to additionally prevent the process from having a terminal to write to -- so if the process is still running and generating output, the kernel will stop it at that point (via ...
You can use call-process the same way as you did, but just replace the third argument by 0. If the third argument is 0, Emacs don't wait for the process and quit without killing it.
SHELL-PROMPT> emacs -Q --batch --eval '(call-process "okular" nil 0 nil)'
Basically, Emacs exits before the subprocess has exited. All you have to do is delay the exit until the subprocess has exited. Since Emacs does not have anything useful to do, you can have it sleep for a while. The following sleeps in a loop until the subprocess does not appear in the process list any longer:
#!/usr/bin/env -S emacs -Q --script # -*- mode: ...
@db48x's answer is undoubtedly the best answer to the question. But it depends on the good graces of screen which conveniently sets the STY variable that sub-processes can check (tmux sets a TMUX variable, so it's equally cooperative). What if you have a less cooperative process that does not set a variable? Doing the "pid stuff", i.e. walking up ...
Here's a somewhat silly implementation of a function that does a call-process and returns its pid (sort-of):
(defun call-process-pid ()
(let (l1 l2)
(setq l1 (list-system-processes))
(call-process "sleep" nil 0 nil "60")
(setq l2 (list-system-processes))
(cl-set-difference l2 l1)))
It's a somewhat cleaner way of doing a ...