Terminals in GUI...

Soldato
Joined
19 Feb 2010
Posts
13,254
Location
London
Hi chaps,

I've noticed in Ubuntu and FC17 I get strange behaviour with catching traps when I run my scripts in the "Terminal" accessed via the GUI.

EG:

Code:
#!/bin/bash

sleeper(){
   echo "TRAP!!!"
   ( sleep 5 && kill -ALRM $$ ) &
}

dieclean(){
   echo "Goodbye!"
   sleep 5
   exit 0
}

trap sleeper ALRM
trap dieclean INT
sleeper
while :
do
   echo "nothing"
   sleep 1
done

This is to run a timer in a script to run a command every X seconds. Really dirty way of "multitasking" in bash.

When I ssh to the machine from within the terminal, it runs fine.

I've diff'd a few things like env outputs but don't see anything obvious.

Am I missing something basic here? SHELL is /bin/bash so I presume the subshell command runs properly.
 
Last edited:
Exactly what sort of 'strange behaviour' are you getting?

As in the signal never seems to reach the running script and isn't trapped.. Really odd.

GUI Shell:

$ ./testtrap
TRAP!!!
nothing
nothing
nothing
nothing
nothing
nothing
nothing
nothing
^CGoodbye!

Now I ssh to myself:
$ ssh localhost
password:
Last login: Wed Jul 11 23:06:08 2012 from localhost
$ ./testtrap
TRAP!!!
nothing
nothing
nothing
nothing
nothing
TRAP!!!
nothing
nothing
nothing
^CGoodbye!
TRAP!!!

This makes no sense to me?

I never see this issue at work as I'm always SSH'd in remotely, but from my home machine I have this weirdness if I launch a terminal from the desktop.
 
Last edited:
Back
Top Bottom