LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-09-2013, 10:14 PM   #1
waddles
Member
 
Registered: Sep 2012
Posts: 373

Rep: Reputation: 0
Trap command


I have created a background process which self destructs after less than a second and returns a SIGALRM to my shell.
While the man page seems to say the response of the trap command is instantaneous I am unsure how that should be interpreted. Does the trap in one function of my program immediately through control from another function in my FG process to the argument of the trap? Then once the function in the argument finishes executing does control revert to where it was at when the trap sprung?
Or does processing have to work through and back to where the trap statement is placed before springing once the shell receives the SIGALRM signal?? I need a reference for a simpleton's tutorial if you aren't unable to address all of the above as I think I have this congratulated with interrupt handling.
 
Old 11-10-2013, 03:25 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,435

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
I'm afraid that isn't very clear what you are asking. Perhaps an example would help.
 
Old 11-12-2013, 12:39 AM   #3
waddles
Member
 
Registered: Sep 2012
Posts: 373

Original Poster
Rep: Reputation: 0
Moving this to a non-*nix forum is NOT helpful!
It is germain to bash shell scripts and Linux processing in this case.
Nevertheless, it sounds like U may not be familiar with interrupts, which usually place their current location within a script on a stack in order to return processing to it following some interrupt code. With a NON-ERRONEOUS signal being emitted from a background script and which kills itself I can presume there is no need to return. Thus my query regarding that phase is understandable as the trap command will just invoke a function and no further action can be taken.
My quandary is: if a non-erroneous signal is emitted from within one function (or background process generated by) of the script and is trapped within a second which causes a third function to process, what action is taken when the third function completes.
I guess that control is returning to the main process from the third function but I can find no definitive documentation.
 
Old 11-13-2013, 09:11 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
Trying to do complicated signal handling in shell scripts is like herding cats.
 
Old 11-13-2013, 11:51 PM   #5
waddles
Member
 
Registered: Sep 2012
Posts: 373

Original Poster
Rep: Reputation: 0
Am closing this query as it appears the information requested is not available here.
 
Old 11-14-2013, 10:27 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
wise move, lots of idiots here.
 
Old 11-14-2013, 01:22 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,396

Rep: Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814Reputation: 814
Quote:
Originally Posted by waddles View Post
While the man page seems to say the response of the trap command is instantaneous I am unsure how that should be interpreted.
Not always instantaneous:
Quote:
3.7.6 Signals

If Bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes. When Bash is waiting for an asynchronous command via the wait builtin, the reception of a signal for which a trap has been set will cause the wait builtin to return immediately with an exit status greater than 128, immediately after which the trap is executed.
Quote:
Originally Posted by waddles
Does the trap in one function of my program immediately through control from another function in my FG process to the argument of the trap?
Timing is not guaranteed: the trap handler starts executing as soon as the signal is recieved (unless something else is being executed, as mentioned above), but there may be some delay between the time the signal is sent and when it is received.

Quote:
Then once the function in the argument finishes executing does control revert to where it was at when the trap sprung?
Or does processing have to work through and back to where the trap statement is placed before springing once the shell receives the SIGALRM signal??
Definitely the first one. I can't point to an actual sentence in the manual, but you can try it and see.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send snmp trap & recieve trap in C program minil Programming 3 07-10-2010 09:22 AM
How to use trap command with a function notepod Linux - Software 12 09-02-2009 02:14 AM
Regarding trap command sharp859 Linux - Newbie 1 05-11-2009 07:35 PM
what does the command do: trap ' ' 1 2 ? manohare Linux - General 2 03-02-2009 05:51 AM
trap command for c? onnyloh Programming 3 09-13-2004 04:06 AM


All times are GMT -5. The time now is 04:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration