Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In bash, how can I initiate a job in a stopped state, as if I started it normally and then immediately pressed Ctrl-Z?

Or as if I had sent SIGSTOP to the process immediately, but without giving the process a chance to execute before it receives the SIGSTOP.

share|improve this question
    
Duplicate of serverfault.com/questions/293632/… ? –  Foon Oct 7 '12 at 11:39
    
Yes, it's an exact duplicate. Unfortunately the other question also has not been answered to my satisfaction. –  nibot Oct 7 '12 at 11:47
add comment

1 Answer

You can start a new subshell, immediatelly stop it, and then (i.e. after makint it run again) run your command. I used the $BASHPID variable to get the PID of the subshell, as $$ still returns the PID of the parent:

( kill -SIGSTOP $BASHPID; my_command )
share|improve this answer
    
Change it to ( kill -SIGSTOP $BASHPID; exec my_command ) and I think we have a winner! –  nibot Oct 7 '12 at 12:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.