Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Semi-OT] Signal app to give stack trace ?



Dwayne Schultz <email@hidden> wrote:

> #!/bin/sh
> tail -f [...] &
>
>This script quits immediately but the tail continues sending output to
>the shell that started the script.
>
>I have another script:
> #!/bin/sh
> java [...] &
>
>This script also quits immediately but standard out appears to be lost
>with it (which is why I couldn't get kill -QUIT to work).
>
>This isn't as critical now but does any know what is going on here?
>The script works as expected when I get rid of the '&'.

Eventually, you're going to have to learn more about Unix programming. A
few things are immediately relevant, though.

1) If your script quits immediately without first redirecting stdio to a
file, then you should do that before exiting the script. Use the >file and
2>file options of /bin/sh. The tcsh options to redirect stdout is the same
(>file), but stderr redirection is different (>&file) (see the redirection
section of 'man tcsh', or search for the literal ">&"). You can also run a
'tail' process to watch the redirected output, or use the Console app,
which basically is a front-end to 'tail' (what's that, coccyx? 12th
vertebra?).

2) Depending on whether a Terminal window is open or not when you run your
shell scripts, you may have to use 'nohup' to run your java command:
nohup java ... >foo 2>bar &
This would be needed because a SIGHUP signal will be sent to remaining
child processes when a shell exits. Normally, a SIGHUP will terminate a
child process. The 'nohup' command ignores SIGHUP, so suppresses this
unwanted termination.

3) When you run a background process with "&", especially when the
control-terminal goes away, a process that tries to output to that terminal
will get a SIGTTOU signal (SIGTTOU can be caught or ignored). The default
reaction to SIGTTOU is to suspend the process, as if by SIGSTOP. I'm not
sure if this is happening with your script and Java program or not. In any
case, it can be avoided by redirecting stdio to files on the command-line.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.