<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Daily Build &#187; script</title>
	<atom:link href="http://blog.bstpierre.org/tag/script/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bstpierre.org</link>
	<description>Software Development, version 3.0</description>
	<lastBuildDate>Wed, 26 May 2010 16:08:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hassle Free Way to Kill Sudo&#8217;d Jobs</title>
		<link>http://blog.bstpierre.org/hassle-free-way-to-kill-sudod-jobs</link>
		<comments>http://blog.bstpierre.org/hassle-free-way-to-kill-sudod-jobs#comments</comments>
		<pubDate>Thu, 13 Aug 2009 00:45:28 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=189</guid>
		<description><![CDATA[Every now and then I have to run a foreground job under sudo that doesn&#8217;t want to die when I hit ^C. Then it&#8217;s a hassle to ^Z, get the pid of the sudo job, and sudo kill that pid.
So I wrote a little script (or a template for scripts) that runs the sudo job [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/lenny-jaunty-packages' rel='bookmark' title='Permanent Link: Using Lenny to Build Jaunty Packages'>Using Lenny to Build Jaunty Packages</a> <small> &lt;shameless_plug&gt; I&#8217;m in the middle...</small></li><li><a href='http://blog.bstpierre.org/pid-file-race' rel='bookmark' title='Permanent Link: An Interesting pid File Race'>An Interesting pid File Race</a> <small> ISC&#8217;s dhcpd uses this code...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Every now and then I have to run a foreground job under sudo that doesn&#8217;t want to die when I hit ^C. Then it&#8217;s a hassle to ^Z, get the pid of the sudo job, and sudo kill that pid.</p>
<p>So I wrote a little script (or a template for scripts) that runs the sudo job in the background (but preserves stdout/stderr) and relies on bash to clean up the job when you ^C the script. Only gotcha with this is that you may have to retype your sudo password when you ^C if your authentication has timed out by the time you get around to killing it.</p>
<pre>#!/bin/bash

function cleanup()
{
    sudo kill $job_pid
    wait $job_pid
    exit 0
}

trap cleanup SIGTERM
trap cleanup SIGINT

sudo long_running_foreground_process &amp;
job_pid=$!
wait</pre>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li><li><a href='http://blog.bstpierre.org/lenny-jaunty-packages' rel='bookmark' title='Permanent Link: Using Lenny to Build Jaunty Packages'>Using Lenny to Build Jaunty Packages</a> <small> &lt;shameless_plug&gt; I&#8217;m in the middle...</small></li><li><a href='http://blog.bstpierre.org/pid-file-race' rel='bookmark' title='Permanent Link: An Interesting pid File Race'>An Interesting pid File Race</a> <small> ISC&#8217;s dhcpd uses this code...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/hassle-free-way-to-kill-sudod-jobs/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
