public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 'shutdown', games
@ 2002-02-14 17:31 hongxun lee
  2002-02-14 17:59 ` Randall R Schulz
  2002-02-14 23:00 ` Contrib: cygwin shutdown script (Re: 'shutdown', games) Chuck Messenger
  0 siblings, 2 replies; 3+ messages in thread
From: hongxun lee @ 2002-02-14 17:31 UTC (permalink / raw)
  To: cygwin mailing list

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

Sorry for the attachment as i know some hate to see them in emails..This 
is my first try of the command 'shutdown', and it did close the windows 
applications right away, but you can see that it can't close Cygwin..Is 
it supposed to be so ?

Does the current version Cygwin include any games already ? i remember i 
saw 'games' somewhere when i updated it.
Thanks


[-- Attachment #2: shutdown.bmp --]
[-- Type: image/bmp, Size: 60062 bytes --]

[-- Attachment #3: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 'shutdown', games
  2002-02-14 17:31 'shutdown', games hongxun lee
@ 2002-02-14 17:59 ` Randall R Schulz
  2002-02-14 23:00 ` Contrib: cygwin shutdown script (Re: 'shutdown', games) Chuck Messenger
  1 sibling, 0 replies; 3+ messages in thread
From: Randall R Schulz @ 2002-02-14 17:59 UTC (permalink / raw)
  To: hongxun lee, cygwin

Hong Xun,

Here's how I reboot (shutdown is analogous, I assume):

         reboot -r now; exit

In practice I always start a couple of SETI@home command-line clients under 
BASH, so I actually do this:

         # Stop the SETI@home clients, initiate reboot and exit BASH
         sahs; reboot -r now; exit

I don't know why, but if I "exit" (or "logout") from BASH while leaving 
running any sub-processes it started (at least these SETI@home clients, 
which are not Cygwin programs), then the window in which BASH was running 
hangs around, though according to the process pane of the Windows Task 
Manager, bash.exe has terminated. If under these circumstances I close the 
window manually (click the close box, i.e.) then the SETI@home clients die, 
the window closes and all proceeds as expected. This part is true 
regardless of whether or not I invoke reboot. A simple test with a detached 
"sleep" command will also illustrate this behavior.

If you want an explanation, it'll have to come from someone who knows the 
relevant innards of Cygwin, Windows and whatnot.

By the way, the "games" category under the Cygwin installer (setup.exe) 
lists these putative games: "fortune" and "robots." I'm sure if you port 
some others to Cygwin, they'd be cheerfully included in the distribution.

Randall Schulz
Mountain View, CA USA


At 17:31 2002-02-14, hongxun lee wrote:
>Sorry for the attachment as i know some hate to see them in emails..This 
>is my first try of the command 'shutdown', and it did close the windows 
>applications right away, but you can see that it can't close Cygwin..Is it 
>supposed to be so ?
>
>Does the current version Cygwin include any games already ? i remember i 
>saw 'games' somewhere when i updated it.
>Thanks


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Contrib: cygwin shutdown script (Re: 'shutdown', games)
  2002-02-14 17:31 'shutdown', games hongxun lee
  2002-02-14 17:59 ` Randall R Schulz
@ 2002-02-14 23:00 ` Chuck Messenger
  1 sibling, 0 replies; 3+ messages in thread
From: Chuck Messenger @ 2002-02-14 23:00 UTC (permalink / raw)
  Cc: cygwin mailing list

  hongxun lee wrote:

>Sorry for the attachment as i know some hate to see them in emails..This 
>is my first try of the command 'shutdown', and it did close the windows 
>applications right away, but you can see that it can't close Cygwin..Is 
>it supposed to be so ?
>

Yeah, that's what I've found, too -- it's a pain to do shutdowns with 
Cygwin programs running.

You prompted me to solve my problem. I've written a script which shuts 
down all Cygwin programs, as nicely as possible. Polite but firm. I've 
included it below. To make it operate properly, invoke it the way it 
says in the comment block at the top:

- Chuck


-------------------------------------

#!/bin/bash

# The purpose of this script is to shut down all running Cygwin programs,
# prior to shutting down the computer. This is a workaround for the problem
# that Windows is unable to shut down Cygwin shells nicely.
#
# The script first gives each Cygwin program a chance -- kill with no flags.
# If that fails, it kills everything that's left with "kill -9".
#
# Unfortunately, I was unable to get Cygwin's "shutdown" to work correctly
# (see note at bottom of script). It would be nice if that worked -- this
# you could simply invoke this script to shut down your computer.
#
# You should link to this program from a desktop shortcut like so (adjust
# as needed):
#
# c:\cygwin\bin\bash.exe --login /usr/local/shut
#
# (assuming you store this in /usr/local/shut).


# Written by Chuck Messenger, 2002 chuckm@rochester.rr.com


tmpf=/tmp/`basename $0`.tmp
logf=/tmp/`basename $0`.log

pid=$$

log() {
echo $1 >> $logf
echo $1
}

is_descendant_of() {
# Returns 0 if $1 is a descendant of $2
# In the code, c is child, $2 is ultimate parent, i is index
local c p

c="$1"
p=""

if [ "$1" == "$2" ]; then
return 0
fi

while [ "$p" != "$2" ]; do
p=`grep "^ *$c " $tmpf | awk '{print $2}'`

if [ -z "$p" ]; then
# No parent for $c
return 1
fi

c=$p
done

# Success -- $1 is a descendant of $2
return 0
}

procname() {
grep "^ *$1 " $tmpf | awk '{print $8}'
}

killem() {
# Don't kill any processes which are part of the parent of this shell script

ps agux | grep -v "^ *PID" > $tmpf

for a in `awk '{print $1}' $tmpf`; do
if is_descendant_of $a $pid ; then
log "Don't kill descendant $a -- `procname $a`"
else
log "kill $1 $a -- `procname $a`"
kill $1 $a 2>> $logf
fi
done

rm $tmpf
}

log "Shutting down at `date`"
log "PID is $pid"

log "Start by killing nicely"
killem

sleep 2

log "No more Mr Nice Guy..."
killem -9

# This ought to be run from a root bash (e.g. from a desktop shortcut).
# In this case, there's no point in trying to kill the parent ($PPID).
# And, I've found that in the case where you call this script from an
# interactive bash shell, that trying to kill the parent process (which 
ought
# to be the interactive bash shell) causes a hung condition.
#
# So, just call it quits...

log "Bye, now..."

# Unfortunately, on Win2k, "shutdown now" causes a reboot rather than a
# shutdown...
#
# And on Win98, "shutdown now" fails, because it complains that the shell
# in which this script is being run must itself first be killed.
#
# So leave out "shutdown now" for now...

#shutdown now



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-15  7:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-14 17:31 'shutdown', games hongxun lee
2002-02-14 17:59 ` Randall R Schulz
2002-02-14 23:00 ` Contrib: cygwin shutdown script (Re: 'shutdown', games) Chuck Messenger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).