Sponsored Content
Top Forums Shell Programming and Scripting Signal trapped during read resumes sleeping Post 302977314 by Corona688 on Friday 15th of July 2016 05:26:53 PM
Old 07-15-2016
I don't think the "resethand" issue is related. Your shell has no issue receiving the interrupt, and does exactly what you told it to do -- wait for input. What needs to be told that something is happening is read. How can you do that? Close whatever it's reading from. Killing tail would do it, for example. Or using a named pipe and forcing it to close.

Code:
#!/bin/ksh

# On ctrl-C, close the read-end of the named pipe.
trap 'echo "Closing FIFO" ; exec 5<&-' INT

mkfifo $$ # Create a named pipe file in the current directory

# Open one end of pipe in background, read from log file,
# write into pipe.
# This will hang until we open the other end,
# so we have to put it in the background.
(exec tail -f /var/log/logfile > $$) &

exec 5<$$ # Open the other end in our shell, into file descriptor 5.
rm /tmp/$$ # Clean up mess

# Read from file descriptor 5 until something forces it to close,
# whether it be tail quitting, the pipe closing, or the apocalypse
while read LINE
do
        echo "$LINE"
done <&5

wait # wait for tail to quit.  Closing our end of the pipe ought to force it to quit (it will get SIGPIPE)

echo "Normal exit"

 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to wakeup sleeping processes

Hi, Could someone please tell me how to wakeup sleeping processes? (i.e. change the process status from "S" to "R" when viewing in ps command). I ran a few programs in the background by "&" which went into "sleep" mode and I want them to run. Any help will be greatly appreciated. Steve (11 Replies)
Discussion started by: stevefox
11 Replies

2. UNIX for Advanced & Expert Users

autosys sample resumes

Hi all, Can anybody send the autosys developer sample resumes. If this is not the correct place to ask please let me know where can I get them. Your help would be appreciated. Thanks Renuka (0 Replies)
Discussion started by: renukasaga01
0 Replies

3. UNIX for Advanced & Expert Users

Trapped Signal HUP

We encountered an issue in our project while using the Interix UNIX (SFU 3.5) and explained our query below. We would be happy if anybody helps us to troubleshoot the problem J In our code the trapping signal for all signals like HUP, INT, QUIT, ILL, TRAP, ABRT, EXCEPT, etc., is initialized in... (4 Replies)
Discussion started by: RAMESHPRABUDASS
4 Replies

4. Shell Programming and Scripting

Trapped in pipe

Hi Is there any way to find out in a single step ( command) the step where the pipe command failed when using multiple commands using pipe . eg : ll *.tar | grep dec | grep december.tar the first step is listing all tar files . Second step constitutes piping that data and doing grep... (5 Replies)
Discussion started by: ultimatix
5 Replies

5. Shell Programming and Scripting

Help on sleeping the script

Hi all, How can i specify to sleep for 24 hours in a script Thanks Firestar (5 Replies)
Discussion started by: firestar
5 Replies

6. Shell Programming and Scripting

Sleep process not sleeping!

I had a script executing every hour to kill a process. I used loop rather than cron to execute it periodically. But now when I am trying to kill that sleep process of 1 hour its not getting killed. it is taking a new PID everytime I kill. To disable the script commenting is the only option... (1 Reply)
Discussion started by: nixhead
1 Replies

7. Shell Programming and Scripting

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... (8 Replies)
Discussion started by: bzk
8 Replies
FIFO(7) 						     Linux Programmer's Manual							   FIFO(7)

NAME
fifo - first-in first-out special file, named pipe DESCRIPTION
A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the file system. It can be opened by multi- ple processes for reading or writing. When processes are exchanging data via the FIFO, the kernel passes all data internally without writ- ing it to the file system. Thus, the FIFO special file has no contents on the file system; the file system entry merely serves as a refer- ence point so that processes can access the pipe using a name in the file system. The kernel maintains exactly one pipe object for each FIFO special file that is opened by at least one process. The FIFO must be opened on both ends (reading and writing) before data can be passed. Normally, opening the FIFO blocks until the other end is opened also. A process can open a FIFO in nonblocking mode. In this case, opening for read only will succeed even if no-one has opened on the write side yet, opening for write only will fail with ENXIO (no such device or address) unless the other end has already been opened. Under Linux, opening a FIFO for read and write will succeed both in blocking and nonblocking mode. POSIX leaves this behavior undefined. This can be used to open a FIFO for writing while there are no readers available. A process that uses both ends of the connection in order to communicate with itself should be very careful to avoid deadlocks. NOTES
When a process tries to write to a FIFO that is not opened for read on the other side, the process is sent a SIGPIPE signal. FIFO special files can be created by mkfifo(3), and are indicated by ls -l with the file type 'p'. SEE ALSO
mkfifo(1), open(2), pipe(2), sigaction(2), signal(2), socketpair(2), mkfifo(3), pipe(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2008-12-03 FIFO(7)
All times are GMT -4. The time now is 08:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy