This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pipes are still buggy in 1.7


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]