[Cialug] Starting two jobs at once
Morris Dovey
mrdovey at iedu.com
Tue Nov 27 18:08:41 CST 2012
On 11/27/12 4:45 PM, Matthew Nuzum wrote:
>
> On Nov 27, 2012, at 4:41 PM, Matthew Nuzum <newz at bearfruit.org> wrote:
>> 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?
>>
>
>
> Alternate googling indicates I may want $!
>
> launch-bg-process &
> bg1pid=$!
> launch-fg-process
> kill $bg1pid
> echo Have a nice day!
>
> I'll give it a try!
Some years ago I wrote a small utility and a callable C function both
named pidof to convert the name of an executable into the PID of the
oldest execution instance.
Later I used the function in a second utility named snuf that takes the
name of a running executable and uses the pidof(char *name) function to
look up the PID and then do a kill(pid,9). Note: you can only snuf your
own processes. :-)
If any of this sounds useful, I can provide C source(s).
More information about the Cialug
mailing list