Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 23rd, 2012, 04:32 PM
Squ3lch Squ3lch is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 11 Squ3lch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 2 m 28 sec
Reputation Power: 0
Signal handling help

I have been working on a Linux programming book and came to an example on signal handling that gave me a hangup. I checked to make sure I copied it alright so I don't believe that's it. Here's the example:
Code:
#!/bin/sh

trap 'rm -f /temp/my_tmp_file_$$' INT
echo creating file /tmp/my_temp_file_$$
date > /tmp/my_temp_file_$$
echo "Press interrupt (CTRL-C) to interrup ...."
while [ -f /tmp/my_tmp_file_$$ ]; do
        echo File Exists
        sleep 1
done
echo The file no longer exists

[highlight]trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_temp_file_$$

echo "press interrupt to interrupt ...."
while [ -f /tmp/my_temp_file_$$ ]; do
        echo File Exists
        sleep 1
done

echo we never get here
exit 0

Which gives me the output:
Code:
creating file /tmp/my_temp_file_18058
Press interrupt (CTRL-C) to interrup ....
The file no longer exists
trap: usage: trap [-lp] [[arg] signal_spec ...]

I'm guessing it's in the trap statement syntax. Perhaps outdated usage?
Thanks for any help.

Reply With Quote
  #2  
Old May 23rd, 2012, 05:33 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 16 m 23 sec
Reputation Power: 1485
I suspect it is because the SIGINT trap having been 'fired' once is no longer active and hence cannot be reset by the 'simple' use of trap INT.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old May 23rd, 2012, 05:59 PM
Squ3lch Squ3lch is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 11 Squ3lch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 2 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by SimonJM
I suspect it is because the SIGINT trap having been 'fired' once is no longer active and hence cannot be reset by the 'simple' use of trap INT.


Wouldn't that mean I would have to press ctrl-c at least once? The output I gave happens immediately after running and then exits. It seems like it only executes the first section of code before exiting on its own. Perhaps the trouble is in creating the file, exiting the loop before the interrupt?

Reply With Quote
  #4  
Old May 23rd, 2012, 06:11 PM
Squ3lch Squ3lch is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 11 Squ3lch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 2 m 28 sec
Reputation Power: 0
Sorry guys. Problems was just a few mixups between tmp and temp. Yet another example of thoroughly checking the code. After that the file does run as expected.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Signal handling help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap