Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: jobs -Z example?



On Mar 16,  7:24am, Atom Smasher wrote:
}
} can someone point me to an example of "jobs -Z" in action?

torch% ps $$
  PID TTY      STAT   TIME COMMAND
 5249 pts/4    Ss     0:00 Src/zsh -f
torch% jobs -Z "You can't see me"
torch% ps $$                     
  PID TTY      STAT   TIME COMMAND
 5249 pts/4    Ss     0:00 You can't see me
torch% print $(< /proc/$$/cmdline )
You can't see me
torch% 

If you mean an explanation of why you'd *want* to do that sort of
thing, the reasons can be a bit obscure.  As one real-world example,
at work we run a job queuing system where a controller process passes
tasks to a set of worker processes.  The worker processes are each a
subshell of a "foreman" script which runs in an infinite loop to keep
track of how many workers are active and to start a new one when one
exits.

So the script at startup runs something like
    jobs -Z "worker:foreman"
and when each subshell starts it runs
    jobs -Z "worker:task"

That way, we can differentiate in "ps" output which process is which,
rather than having them all appear to be copies of the same script.
If we want to shut the system down cleanly, we kill the foreman and
let the workers die off as their tasks complete.

Yes, we could do this by having the foreman write it's PID to a file
instead, etc.  This just makes it obvious when running "top" or other
system monitoring.



Messages sorted by: Reverse Date, Date, Thread, Author