| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 |
| X-Spam-Check-By: | sourceware.org |
| X-Authority-Analysis: | v=1.0 c=1 a=6pmAzL6ttLSS9L_ppjwA:9 a=5NDYJh-xaDU7NmZMveoA:7 a=ob64pUpIhOdT50cbCJ4OTEZVOsEA:4 |
| Message-ID: | <4B8DC616.9020302@columbus.rr.com> |
| Date: | Tue, 02 Mar 2010 21:14:46 -0500 |
| From: | Paul McFerrin <pmcferrin AT columbus DOT rr DOT com> |
| Reply-To: | pmcferrin AT columbus DOT rr DOT com |
| User-Agent: | Thunderbird 2.0.0.23 (Windows/20090812) |
| MIME-Version: | 1.0 |
| To: | Cygwin <cygwin AT cygwin DOT com> |
| Subject: | pipes are still buggy in 1.7 |
| X-IsSubscribed: | yes |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
Hi folks:
I've been tryinh to get the following code to work. What I trying to do
is to run a ps command 2 times (with 3 secs separation) and have the awk
program capture the output kill all processes for a shutdown script.
Something is hanging. It does not run and control-C & controol-\ does
not work. Here is the script:
.$ cat /lbin/shutdown
#!/bin/bash
#
# Shutdown the cygwin system
#
# First we send SIGKILL to all process NOT in our process
# group. Then after a 5-second sleep, we send SIGKILL.
#
# The last step is to kill off our process group.
#
# Written: Paul E. McFerrin 02/15/02
#
ME=`basename $0`
TMP=/tmp/${ME}_tmp # generated script name
>$TMP
if [ -z "$CONSOLE_TTY" ]
then
echo "You must execute $ME in the console (first) window!!"
exit 2
fi
echo -e "\nShutting down CYGWIN ..."
PATH=/usr/local/apache/bin:$PATH
if [ -f /usr/local/apache/bin/apachectl ]
then
apachectl stop
fi
AWKPGM='
# PID PPID PGID WINPID TTY UID STIME COMMAND
# 442949 1 442949 4294461843 0 500 02:35:28 /usr/bin/KSH
# 652513 1 652513 4294323867 0 500 02:35:43 /usr/bin/RXVT
/PID/ { next }
{
if( $1 == pid ) {
ourpgrp = $3
}
pgroup[$3 ""] = $3
#next
}
{
nonspec[$1 ""] = $1
}
END {
print "exec 2>/dev/null" >TMP
print "# Our process group = " ourpgrp >>TMP
for( g in pgroup ) {
if( g != ourpgrp ) {
print "echo + kill -15 -" g >>TMP
print "kill -15 -" g >>TMP
}
}
print "sleep 5" >>TMP
for( g in pgroup ) {
if( g != ourpgrp ) {
print "echo + kill -9 -" g >>TMP
print "kill -9 -" g >>TMP
}
}
print "# killing off our process group" >>TMP
for( g in pgroup ) {
if( g == ourpgrp ) {
print "echo + kill -9 -" g >>TMP
print "kill -9 -" g >>TMP
}
print "echo + kill ALL -9 1 " >>TMP
print "kill -9 1" >>TMP
}
print "# killing off remaining processes, if any" >>TMP
for( pid in nonspec ) {
if( pid != $1 ) {
print "echo # nonspec = " pid >>TMP
# kill all other processes, except for me
if (NF == 8) {
print "echo + kill -9 " pid >>TMP
print "kill -9 " pid >>TMP
}
}
}
}'
if [ -p /tmp/pipe1 ]
then
rm -f /tmp/pipe1
fi
mknod /tmp/pipe1 p
exec 1>/tmp/pipe1 # keep shell opened into pipe1
gawk "$AWKPGM" TMP=$TMP pid=$$ </tmp/pipe1
ps -a >/tmp/pipe1
sleep 3
ps -a >>pipe1
1>&- # now we close the pipe1
rm -f /tmp/pipe1
if [ -s $TMP ]
then
trap '' 15 # shields up!
#/bin/sh $TMP
cat $TMP
fi
# in theory, the exit should not be reached as we should have been killed
exit 0
Is this a bug in pipes??
- Paul
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |