the way to handle the USR1

the way to handle the USR1

Post by Chris Yan » Wed, 05 Apr 2000 04:00:00



folks,
        i developed a script under Solaris which ran
ksh88i as shell and it worked ok. but i ran this under
another machine having the same environment with exception
to the version of ksh -- ksh93, it failed. the point
the script break out appear to be more relative to the way
the different version ksh handle the USR1, is there anyone
aware of this, and please help ?

--
Thanks
Chris Yang
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                                  +
+ Chris Yang                    ("`-''-/").___..--''"`-._          +

+ http://gnu.in-china.com        (_Y_.)'  ._   )  `._ `. ``-..-'   +
+ (tel)0532 8702000 x5221      _..`--'_..-_/  /--'_.' ,'           +
+ (pager)95812-8073661        (il),-''  (li),'  ((!.-'             +
+                                                                  +
+ http://gdcsr60.gdc.lucent.com/~chrisy                            +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 
 
 

the way to handle the USR1

Post by Dan Merc » Thu, 06 Apr 2000 04:00:00




> folks,
>    i developed a script under Solaris which ran
> ksh88i as shell and it worked ok. but i ran this under
> another machine having the same environment with exception
> to the version of ksh -- ksh93, it failed. the point
> the script break out appear to be more relative to the way
> the different version ksh handle the USR1, is there anyone
> aware of this, and please help ?

You are better off posting the script.  More likely you are running into
a function problem.  In ksh,  there are two methods of declaring
a function,  POSIX style and Korn style:

POSIX:

   myfun() { list; }

Korn:

   function myfun { list; }

In ksh88,  they behave identically.  But in making ksh93 POSIX
compliant,  Korn had to dumb down the POSIX style behavior.  This
affects a wide variety of issues:

   $0 in POSIX is set to the name of the $0 of the shell
   $0 in Korn is set to the name of the function
   variables typeset in the function are local in Korn, global in POSIX
   In Korn,  traps caught by the caller (script) are reset to their default
   action inside the function.   A trap condition that is not caught or
   ignored by the function causes the function to terminate and the
   condition to be passed on to the caller. In POSIX share all traps
   with the caller.  
   Errors within a Korn function exit the function
   and return control to the calling script.  Errors within a POSIX function
   cause the calling script to exit.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

the way to handle the USR1

Post by Stephane Titar » Thu, 06 Apr 2000 04:00:00


Hi all,
I have two comments:
1) the function syntax with keyword function does follow ksh88 behaviour

   POSIX based its shell on the common features of different
implementations
   (partly Korn,partly csh, partly intersection of features found in
different OS).
this limits the functionality; at the same time, lots of issues were
left
   unspecified. The most limiting POSIX features sometimes were not
implemented
   see HP-UX posix shell o Solaris ksh.
   Always check your manpages.
   Also built-in alternative test syntax is not POSIX e.g [[ -f myfile
]] ...

2) Beware of signal handling.
   Normally when you set up a signal-handler, you should do your cleanup

   and little else, and then exit.
   Inside an interpreter that does a lot of dynamic allocation, you run
into
   the problem of re-entrancy of malloc. If you have perl somewhere,
this is
   a known problem: the interpreter may crash at arbitrary times if you
do too
   much signal handling -- look at perldoc and camel book .

let me give one example with USR1

I want to set up temporization so that every N=60 seconds I do
something.
One way would be to have a child sending SIGUSR to its parent.

tempor(){
...whatever

Quote:}

trap tempor USR1

timer(){
while true
do
  kill -USR1 $$
sleep 60
done

Quote:}

( timer ) &

...some infinite loop or whatever

some variant of such a script dumped core at arbitrary times in HP-UX
and Solaris
got some strange behaviour with bash: No core but sometimes the script
would stop
saying it received a SIGINT ????
could be working fine a few days.

I don't know what you want to do with USR1
my workaround was to use poor man's semaphores i.e a 0-sized file

cheers

  sgt19.vcf
< 1K Download
 
 
 

the way to handle the USR1

Post by Stephane Titar » Thu, 06 Apr 2000 04:00:00


Hi all,
I have two comments:
1) the function syntax with keyword function does follow ksh88 behaviour

   POSIX based its shell on the common features of different
implementations
   (partly Korn,partly csh, partly intersection of features found in
different OS).
this limits the functionality; at the same time, lots of issues were
left
   unspecified. The most limiting POSIX features sometimes were not
implemented
   see HP-UX posix shell o Solaris ksh.
   Always check your manpages.
   Also built-in alternative test syntax is not POSIX e.g [[ -f myfile
]] ...

2) Beware of signal handling.
   Normally when you set up a signal-handler, you should do your cleanup

   and little else, and then exit.
   Inside an interpreter that does a lot of dynamic allocation, you run
into
   the problem of re-entrancy of malloc. If you have perl somewhere,
this is
   a known problem: the interpreter may crash at arbitrary times if you
do too
   much signal handling -- look at perldoc and camel book .

let me give one example with USR1

I want to set up temporization so that every N=60 seconds I do
something.
One way would be to have a child sending SIGUSR to its parent.

tempor(){
...whatever

Quote:}

trap tempor USR1

timer(){
while true
do
  kill -USR1 $$
sleep 60
done

Quote:}

( timer ) &

...some infinite loop or whatever

some variant of such a script dumped core at arbitrary times in HP-UX
and Solaris
got some strange behaviour with bash: No core but sometimes the script
would stop
saying it received a SIGINT ????
could be working fine a few days.

I don't know what you want to do with USR1
my workaround was to use poor man's semaphores i.e a 0-sized file

cheers

  sgt19.vcf
< 1K Download
 
 
 

the way to handle the USR1

Post by Chris Yan » Sat, 08 Apr 2000 04:00:00


my script invokes another binary executable file
which will sends back a USR1 to the process of my
script :

...
trap 'INIT=1;echo Catched' USR1
(executable &)
....

but the same code runs into two different result:
under ksh88i, works fine, USR1 captured. but under
ksh93 nothing happen. when i added following lines
ahead of my script (force to invoke ksh88)

if [[ `~` == ~ ]]; then
        exec /opt/bin/ksh88 $0
fi
it works either, i determined that there's some tricky
differences between ksh88 and ksh93 on handling SIGUSR1
but i don't know what it be

Chris.

 
 
 

the way to handle the USR1

Post by Dan Merc » Sat, 08 Apr 2000 04:00:00




> my script invokes another binary executable file
> which will sends back a USR1 to the process of my
> script :

> ...
> trap 'INIT=1;echo Catched' USR1
> (executable &)
> ....

> but the same code runs into two different result:
> under ksh88i, works fine, USR1 captured. but under
> ksh93 nothing happen. when i added following lines
> ahead of my script (force to invoke ksh88)

> if [[ `~` == ~ ]]; then
>    exec /opt/bin/ksh88 $0
> fi
> it works either, i determined that there's some tricky
> differences between ksh88 and ksh93 on handling SIGUSR1
> but i don't know what it be

> Chris.

FWIW,  ksh88 resets traps for subshells.  Ksh93 passes them:

   $ trap
   $ trap 'echo usr1' usr1
   $ trap
   16:echo usr1
   $ (trap)
   $ ksh93
   $ trap
   $ trap 'echo usr1' usr1
   $ trap
   trap -- 'echo usr1' USR1
   $ (trap)
   trap -- 'echo usr1' USR1

How is your executable sending usr1 back to the shell?  If you are
sending it to the parent process id,  you are getting the pid of
the subshell,  not the shell.  You could pass the process id

   (executable $$ &)

Why are you starting executable in a subshell?

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

1. Best ways to handle function keys?

  Here's my problem - I'm writing an app that makes use of function
  and extended keys (ie F5, Ctrl-w, etc), and want it to be
  usable on text terminals.  I've seen some stuff that does this,
  but it depends on X to do some keymap translations, displaying text in an
  xterm - I'd like to avoid that.  Is there a "general" way to
  do this?  I've checked out the termcap stuff, and the termcaps
  I have don't seem to have entries for the extended and function
  keys (am I just missing them?).  Any help would be appreciated!  Thanks.

--
"Deep in the human unconscious is a pervasive need for a logical universe
 that makes sense.  But the real universe is always one step beyond logic"
                - Frank Herbert

2. RH 6.2 boot fail...

3. Painless Ways to Handle Password Expirations

4. kernel past 2.2.5 failing to boot

5. Is there ways that apache can handle requests with different priority

6. test closes stdin - why?

7. FreeBSD 4.5 - Apache 1.3.26 - kill USR1 causes server to terminate, not restart

8. Creation of unique filename for temp file.

9. Apache & USR1

10. COMMENT TRAPER UN SIGNAL USR1???

11. Q:HOW to increase the space on /home and decrease space on /usr1?

12. mounting /usr1 to /usr/training

13. NFS Server: Blocked attempt of linuxhost to mount /usr1