Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK Beginning Linux Programming, 3rd Edition
This is the forum to discuss the Wrox book Beginning Linux Programming, 2nd Edition by Richard Stones, Neil Matthew, Alan Cox; ISBN: 9780764543739
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Beginning Linux Programming, 3rd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 13th, 2008, 01:02 AM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default chap 2 about trap INT

there is something wrong with "trap INT"
the code is :
##############´úÂëÈçÏ£¬the red is wrong###############
#!/bin/sh

trap 'rm -f /tmp/my_tmp_file_$$' INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$

echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo The file no longer exists

trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$

echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done

echo We never get here

exit 0



##########################

i change "trap INT" to "trap 2" and it right.why???

###########the answers#############
# ./_trap
creating file /tmp/my_tmp_file_7456
Press interrupt (Ctrl-C) to interrupt....
File exists
File exists
The file no longer exists
trap: usage: trap [-lp] [arg signal_spec ...]
##############################

ÎÒÔÚ¿´beginning linux programmingk( linux³ÌÐòÉè¼ÆµÚÈý°æ£©
ÊéÖеڶþÕ shell±à³Ì ÓÐÒ»¸ö´úÂ룬ִÐгö´í¡£
Ö´Ðнá¹ûÈçÏ£º
°Ñ´úÂëÖС°trap INT¡±¸ÄΪ¡°trap 2¡±¼´¿ÉÒÔÖ´ÐУ¬Çë½ÌÕâÊÇΪ ²Ã´£¿

´úÂëÈçÏ£º


###########Ö´Ðнá¹û#############
# ./_trap
creating file /tmp/my_tmp_file_7456
Press interrupt (Ctrl-C) to interrupt....
File exists
File exists
The file no longer exists
trap: usage: trap [-lp] [arg signal_spec ...]
##############################


##############´úÂëÈçÏ£¬ºìÉ«µÄΪ Ð޸ĵĵط½###############
#!/bin/sh

trap 'rm -f /tmp/my_tmp_file_$$' INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$

echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done
echo The file no longer exists

trap INT
echo creating file /tmp/my_tmp_file_$$
date > /tmp/my_tmp_file_$$

echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f /tmp/my_tmp_file_$$ ]; do
echo File exists
sleep 1
done

echo We never get here

exit 0



##########################



 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to trap errors starnet SQL Server 2000 1 October 6th, 2006 11:05 AM
GetObject Trap bostek VBScript 2 November 24th, 2004 02:39 AM
Disable/Trap msgBox?? adelgado Access VBA 1 September 13th, 2004 03:54 PM
How can I trap for a connection error cdukes77@bellsouth.net Classic ASP Databases 1 April 27th, 2004 03:09 AM
Trap for empty recordset in a SP Mitch Access VBA 2 September 5th, 2003 04:47 PM



All times are GMT -4. The time now is 08:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.