[Cialug] Starting two jobs at once

Matthew Nuzum newz at bearfruit.org
Tue Nov 27 16:41:44 CST 2012


On Nov 27, 2012, at 4:23 PM, Barry Von Ahsen <barry at vonahsen.com> wrote:

>> 1.
>> Start a task and background it with &
>> Start the foreground task and wait until it completes
>> Kill the background task
>> 
>> The prob is I'm not sure really how to kill a background task once it's in the background
>> 
> 
> 
> you can use jobs and/or fg to manage background tasks, they're shell built-ins (csh and sh, at least)
> 
> you know when you forget the & and you have to ^Z then bg?  fg is the opposite
> 


Right, I know about fg but then you're stuck with a daemon in the foreground and you need to ctrl+c it as well, right? I just want it to die (gracefully if possible). I can imagine in an upcoming project actually having three tasks, sass, mongodb and a python or js based web server. That means ctrl+c ctrl+c ctrl+c.

Zachary, echo $$ returns the PID of the last process started? I tried googling it but didn't get anything remotely helpful. :-)

If so, that might be the solution I'm looking for.

In psuedo code I could do something like:

launch-bg-process &
p1pid=`echo $$`
launch-fg-process
kill $p1pid
echo Have a nice day!

Does that look right?

-- 
Matthew Nuzum
newz2000 on freenode, skype, linkedin and twitter

♫ You're never fully dressed without a smile! ♫


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4136 bytes
Desc: not available
URL: <http://cialug.org/pipermail/cialug/attachments/20121127/62382b40/attachment.bin>


More information about the Cialug mailing list