Sponsored Content
Top Forums Shell Programming and Scripting ksh interrupt read instruction with signal Post 302577894 by bzk on Wednesday 30th of November 2011 07:47:47 AM
Old 11-30-2011
ksh interrupt read instruction with signal

Dear shell experts,

I spent last few days porting ksh script from ksh88/SunOS to ksh93/Linux.
Basically, things are going well and I do not have too much troubles porting ks88 script to ksh93, but I stuck on one item. It's about sending and handling the signal.
I found two similar topics on this forum, but hints provided there, do not resolve my problem (

https://www.unix.com/shell-programmin...d-command.html
https://www.unix.com/shell-programmin...t-timeout.html )

Please consider following simple script.

Code:
  #!/bin/ksh
  typeset TEXT=""
  
  trap 'echo "got a signal!"' USR1
  
  echo "put some text here.... my pid is $$"
  read TEXT
  echo "I'm done"
  
  exit 0

Run the script and hold on read instruction (do not put any data).
Now, from other terminal, send USR1 signal to this script. Please note, ksh88/SunOS and ksh93/Linux behave different way here.

# ksh88/SunOS”
[OUTPUT]
put some text here.... my pid is 11325

got a signal!
I'm done
[/OUTPUT]

# ksh93/Linux #
[OUTPUT]
put some text here.... my pid is 29688
got a signal!

# It still sits in read instruction. You need to hit entrer to continue.
[/OUTPUT]

I was expecting ksh handling the signal this way:
1. break current system call (read instrluction in this case)
2. execute trap instructions
3. continue with next instruction after the read.

This flow work on the SunOS/ksh88. Read instruction is interrupted, but not with ksh93/Linux. With ksh93/Linux I'm not able to break read instruction using signal and that's my concern here.

Please note, I can not use “-t” option for read, since my script must be backward compatible with ksh88. I either can't use “line” command, since it's not available on my linux machine.
I would appreciate any hint/suggestions how to break read instruction.
Kind Regards,
bzk
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Interrupt signal Control C takes too long to terminate a process

I have a process to terminate, and when keying Control C/ kill -int , it takes 15 minutes to half an hour to terminate the process. I've tried using kill -2, or keying control c twice, however the process seem to be killed abruptly, without writing into the log file. So the only way in order to... (8 Replies)
Discussion started by: paqui
8 Replies

2. Shell Programming and Scripting

ksh read timeout

any idea on how to timeout the read statement for ksh? for bash u can use read -t option -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has ... (2 Replies)
Discussion started by: ashterix
2 Replies

3. Shell Programming and Scripting

is there any way to read a line twice in KSH

Hi All, Is there any way to read the previous line in file reading ? or is there any way to read a line twice in KSH ? thanks in advance !! Srini (6 Replies)
Discussion started by: Srini75
6 Replies

4. Shell Programming and Scripting

read from console in ksh

I am stuck with a problem while reading data from a file.. while do read line #do some operations and if some condition is satisfied, ask the user to enter his choice. # using the choice continue operations. done < fileBeingRead.txt The... (4 Replies)
Discussion started by: ajaykumarns
4 Replies

5. Programming

how to discard instruction from previous signal

hello everyone, I'm having a problem doing signal handling so I post this thread to see if I could get help. I want asynchronous signal handling, that means when I'm processing a signal (signal 1), if the same signal comes (signal 2) that signal (signal 2) shall be processed; and moreover,... (7 Replies)
Discussion started by: nvhoang
7 Replies

6. UNIX for Dummies Questions & Answers

simple way to read an array in ksh

hi, I'm a newbie to shell scripting. I wanted to initialise an array using basic for loop and read it. Then i want to print it as a .CSV file.. Any help would me much appreciated.. (1 Reply)
Discussion started by: pravsripad
1 Replies

7. UNIX for Advanced & Expert Users

Interrupt storm detected on "irq 20" throttling interrupt source

I receive the following warning messages on a very new machine which has FreeBSD 8.1 x64 installed on it: Interrupt storm detected on "irq 20" throttling interrupt source It is unclear what this means and what its origins are (motherboard? CPU? RAM?). I can start the desktop and the message is... (4 Replies)
Discussion started by: figaro
4 Replies

8. UNIX for Advanced & Expert Users

Is there any shell command to show which interrupt handler handle which interrupt number?

Hi, all: Is there any shell command to show which interrupt handler handle which interrupt number in the system? li,kunlun (5 Replies)
Discussion started by: liklstar
5 Replies

9. Shell Programming and Scripting

ksh while read issue

Hello, I have used a chunk of ksh script similar to this in many places without any issue: while : do print; read OPTION?"Enter a number (q to quit): " expr ${OPTION} + 1 >/dev/null 2>&1 CHECKVAL=$? if }" != ${OPTION} ]; then ... (2 Replies)
Discussion started by: port43
2 Replies

10. Shell Programming and Scripting

Signal trapped during read resumes sleeping

Greetings. This is my first post in this forum; I hope y'all find it useful. One caveat: "Concise" is my middle name. NOT! :D I am almost done with a shell script that runs as a daemon. It monitors a message log that is frequently written to by a database server but it it works my client will... (2 Replies)
Discussion started by: jakesalomon
2 Replies
All times are GMT -4. The time now is 08:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy