Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Trap Computer Shutdown Signal

  1. #1
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Question Trap Computer Shutdown Signal

    Hi! I've got a shell script that downloads and displays a sunmap as the background every 60 seconds. The program reverts the background to the original when it ends by using a trap statement - everything works fine apart from when the script is ended by a computer shutdown, in which case the background is not reverted. This is part of a small Launchpad project and this issue is putting on hold a merge, so any help would be greatly appreciated.

    View File - Download File - View Bug

    Thanks!


    SOLVED
    Turns out trap doesn't work with loops, use the wait statement to fix this.
    Last edited by Penguin Guy; July 13th, 2010 at 06:24 PM.

  2. #2
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Trap Computer Shutdown Signal

    I must be misunderstanding you. If you're about to shut down the computer, why do you care whether it gets reverted or not?

  3. #3
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by trent.josephsen View Post
    If you're about to shut down the computer, why do you care whether it gets reverted or not?
    Because when you next start the computer you'll have no wallpaper.

  4. #4
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by Penguin Guy View Post
    Because when you next start the computer you'll have no wallpaper.
    Oh! I set my wallpaper in .xinitrc, so that never even occurred to me.

    Maybe SIGKILL? But I would have expected SIGTERM to work.

  5. #5
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by trent.josephsen View Post
    Maybe SIGKILL? But I would have expected SIGTERM to work.
    I'm pretty sure you can't trap SIGKILL, but I'll give it a go anyway.

    EDIT: Nope, that doesn't work either.
    Last edited by Penguin Guy; July 12th, 2010 at 08:43 PM.

  6. #6
    Join Date
    Jul 2008
    Location
    England
    Beans
    866

    Re: Trap Computer Shutdown Signal

    From searching the net it seems that SIGTERM should work.

    However if it doesn't when the system shuts down rc.d scripts are called and maybe you could add something in there to notify your program.

    Below is the link I plagiarised this information from

    http://stackoverflow.com/questions/2...tdown-on-linux

    Hope it is of some help.

    Paul

  7. #7
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by PaulM1985 View Post
    From searching the net it seems that SIGTERM should work.

    However if it doesn't when the system shuts down rc.d scripts are called and maybe you could add something in there to notify your program.

    Below is the link I plagiarised this information from

    http://stackoverflow.com/questions/2...tdown-on-linux

    Hope it is of some help.

    Paul
    I'm already using SIGTERM, and rc.d scripts are really a bit advanced for this program. Are there any other possible suggestions?

  8. #8
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by Penguin Guy View Post
    I'm pretty sure you can't trap SIGKILL, but I'll give it a go anyway.
    No, of course not. I meant that perhaps your script is being sent KILL instead of TERM, even though TERM should end the script. Sorry for miscommunicating.

  9. #9
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Trap Computer Shutdown Signal

    Quote Originally Posted by trent.josephsen View Post
    I meant that perhaps your script is being sent KILL instead of TERM, even though TERM should end the script.
    Looks like it is, but why?

  10. #10
    Join Date
    Jan 2008
    Beans
    69

    Re: Trap Computer Shutdown Signal

    Shell scripts are too high level to catch SIGTERM or SIGKILL. Maybe theres a way to do it, but I don't think trapping a signal will do it, seeing as the signal is sent to BASH/shell rather than your script. Unless BASH will relay this information to a shell script, which I don't think it does.
    ------------------

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •