Sponsored Content
Full Discussion: trap command
Top Forums UNIX for Dummies Questions & Answers trap command Post 302512049 by Straitsfan on Friday 8th of April 2011 09:12:34 AM
Old 04-08-2011
Methyl:
I tried setting the key but it didn't work:

stty: illegal option -- INT
usage: stty [-a|-e|-g] [-f file] [options]
trap: usage: trap [-lp] [arg signal_spec ...]


I wish I had a unix manual of some sort --

I typed trap -l and got this (on my iMac at home -- still the same result when I ran the script) :

1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE
9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGURG
17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD
21) SIGTTIN 22) SIGTTOU 23) SIGIO 24) SIGXCPU
25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
29) SIGINFO 30) SIGUSR1 31) SIGUSR2

so I'm guessing that the interrupt signal is SIGINT.

Even with this, the same thing happens -- ^C is displayed on the screen and it goes right back to the script. If I type control z it says this :

[1]+ Stopped sleep 60

and goes right back to the script -- and the job number increases by one every time I type it. I can't stop the script from running. The only way I can is to quit terminal, at which point I get a message saying the following processes will be stopped -- bash, and however many sleep jobs it's running.

Last edited by Straitsfan; 04-08-2011 at 11:22 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using TRAP command

I'm using the trap command to capture any signals received whilst my script is running. How's the best way of writing the signal and any other error messages to a file/error log' without having to type '2>$1' on the command line after the script name? Cheers (3 Replies)
Discussion started by: dbrundrett
3 Replies

2. UNIX for Dummies Questions & Answers

trap command

i have the following script that displays the current time until the user presses CTR + c.... but it does not work properly.... Something is not right with the trap command... Help plz... :confused: # script to continuously display current time. # if script is terminated trap signal... (3 Replies)
Discussion started by: onlyc
3 Replies

3. UNIX for Dummies Questions & Answers

trap command

Dear All could you please explain me what does the trap command do and how I can write a program which can work as a trap command(in C Language). (1 Reply)
Discussion started by: mobile01
1 Replies

4. Programming

trap command in Unix

Could anybody tell me what the trap command does and how it performs the action it does. I had read the trap manual page but it is too concise that nothing is clear about it. Please tell how it works. (1 Reply)
Discussion started by: mobile01
1 Replies

5. Shell Programming and Scripting

Use of TRAP Command

Hi, I would like to know the use of TRAP command. I am very new to the UNIX environment. I have just started learning the basic. So please teach me in a very simple way to understand. Also i would like to know the use of following command: trap 'dialog --msgbox "Script Aborted1" 6 50 ;... (2 Replies)
Discussion started by: Deepakh
2 Replies

6. Shell Programming and Scripting

Cntl+z Trap is not detecting ??? Help required to add a trap detection ???

Hi folks, I have tried to add some trap detection in the below script....this script is used to monitor database activities...in a rather awkward way :rolleyes:.... The idea behind adding trap is that....this script creates lots of temporary files in the running folder to store the count... (1 Reply)
Discussion started by: frozensmilz
1 Replies

7. UNIX for Advanced & Expert Users

trap command

Hello experts! I need to know the use of trap command please In one of our program we have trap "rm -f temp1 ; exit 1" 1 2 15 0 and program always exit with 1 there is a rm -f temp1 as well at the end of the program as rm -f temp1 exit 0 when I test a probram with set... (4 Replies)
Discussion started by: ramshree01
4 Replies

8. Shell Programming and Scripting

trap command

dear all; I can't under stand what does "trap" command do: for example see below: trap "echo; echo no interrupts >&2; sleep 3" 2 3 15 Plz , can any body explain the action of this command? BR (3 Replies)
Discussion started by: ahmad.diab
3 Replies

9. Homework & Coursework Questions

VM trap may work differently than a pure install trap.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: That is the last reply I received from my instructor, and I'm looking for some alternatives. When using... (2 Replies)
Discussion started by: newuser45
2 Replies

10. Shell Programming and Scripting

Trap command not working

Hi Folks - For some reason, my trap command is not working. It's placed just prior to a normal exit: #:: ------------------------------------------------------------------------ #::-- Script Name: LCM_Backup.sh #:: #::-- Description: This script leverages Utility.sh to perform LCM... (16 Replies)
Discussion started by: SIMMS7400
16 Replies
signal(4)						     Kernel Interfaces Manual							 signal(4)

NAME
signal, signal.h - Contains definitions and variables used by signal functions DESCRIPTION
The /usr/include/signal.h file defines the signals described in the following table. ------------------------------------------------------------------------------ Signal Number Meaning ------------------------------------------------------------------------------ SIGHUP 1 Hangup. SIGINT 2 Interrupt. SIGQUIT 3 Quit. (1) SIGILL 4 Invalid instruction (not reset when caught). (1) SIGTRAP 5 Trace trap (not reset when caught). (1) SIGABRT 6 End process (see the abort() function). (1) SIGEMT 7 EMT instruction. SIGFPE 8 Arithmetic exception, integer divide by 0 (zero), or floating-point exception. (1) SIGKILL 9 Kill (cannot be caught or ignored). SIGBUS 10 Specification exception. (1) SIGSEGV 11 Segmentation violation. (1) SIGSYS 12 Invalid parameter to system call. (1) SIGPIPE 13 Write on a pipe when there is no process to read it. SIGALRM 14 Alarm clock. SIGTERM 15 Software termination signal. SIGURG 16 Urgent condition on I/O channel. (2) SIGSTOP 17 Stop (cannot be caught or ignored). (3) SIGTSTP 18 Interactive stop. (3) SIGCONT 19 Continue if stopped. (4) SIGCHLD 20 To parent on child stop or exit. (2) SIGTTIN 21 Background read attempted from control terminal. (3) SIGTTOU 22 Background write attempted from control terminal. (3) SIGIO 23 Input/Output possible or completed. (2) SIGXCPU 24 CPU time limit exceeded (see the setrlimit() function). SIGXFSZ 25 File size limit exceeded (see the setrlimit() function). SIGVTALRM 26 Virtual time alarm (see the setitimer() function). SIGPROF 27 Profiling time alarm (see the setitimer() function). SIGWINCH 28 Window size change. (2) SIGINFO 29 Information request. (2) SIGUSR1 30 User-defined signal 1. SIGUSR2 31 User-defined signal 2. Notes to table: Default action includes creating a core dump file. Default action is to ignore these signals. Default action is to stop the process receiving these signals. Default action is to restart or continue the process receiving these signals. The three types of actions that can be associated with a signal: SIG_DFL, SIG_IGN, or a pointer to a function are described as follows: Default action: signal-specific default action. Except for those signal numbers marked with a (2), (3), or (4), the default action for a signal is to end the receiving process with all of the consequences described in the _exit() system call. In addition, a memory image file is created in the current directory of the receiving process if the signal parameter is one for which a superscript 1 appears in the preceding list and the following conditions are met: The effective user ID and the real user ID of the receiving process are equal. An ordinary file named core exists in the current directory and is writable, or it can be created. If the file must be created, it will have the following prop- erties: The access permission code 0600, modified by the file creation mask (see the umask() function). A file owner ID that is the same as the effective user ID of the receiving process. A file group ID that is inherited from the containing directory (if the file system is mounted grpid) or from the owning process (if the file system is mounted nogrpid). For signal numbers marked with a superscript 4, the default action is to restart the receiving process if it is stopped, or to con- tinue execution of the receiving process. For signal numbers marked with a superscript 3, the default action is to stop the execution of the receiving process temporarily. When a process stops, a SIGCHLD signal is sent to its parent process, unless the parent process has set the SA_NOCLDSTOP bit. While a process is stopped, any additional signals that are sent to the process are not delivered until the process is continued. An exception to this is SIGKILL, which always terminates the receiving process. Another exception is SIGCONT, which always causes the receiving process to restart or continue running. A process whose parent has ended shall be sent a SIGKILL signal if the SIGTSTP, SIGTTIN, or SIGTTOU signals are generated for that process. For signal numbers marked with a superscript 2, the default action is to ignore the signal. In this case, delivery of the signal has no effect on the receiving process. If a signal action is set to SIG_DFL while the signal is pending, the signal remains pending. Ignore signal. Delivery of the signal has no effect on the receiving process. If a signal action is set to SIG_IGN while the signal is pending, the pending signal is discarded. Note that the SIGKILL and SIGSTOP signals cannot be ignored. Catch signal. Upon delivery of the signal, the receiving process is to run the signal-catching function specified by the pointer to function. The signal-handler subroutine can be declared as follows: void handler(signal) int signal; The signal parameter is the signal number. A new signal mask is calculated and installed for the duration of the signal-catching function (or until sigprocmask() or sigsuspend() sys- tem calls are made). This mask is formed by taking the union of the process signal mask, the mask associated with the action for the signal being delivered, and a mask corresponding to the signal being delivered. The mask associated with the signal-catching function is not allowed to block those signals that cannot be ignored. This is enforced by the kernel without causing an error to be indicated. If and when the signal-catching function returns, the original signal mask is restored (modified by any sigprocmask() calls that were made since the signal-catching function was called) and the receiving process resumes execution at the point it was interrupted. The signal-catching function can cause the process to resume in a different context by calling the longjmp() subroutine. When the longjmp() subroutine is called, the process leaves the signal stack, if it is currently on it, and restores the process signal mask to the state when the corresponding setjmp() call was made. Once an action is installed for a specific signal, it remains installed until another action is explicitly requested (by another call to the sigaction() system call), or until one of the exec system calls is called. If a signal action is set to a pointer to a function while the signal is pending, the signal remains pending. When signal-catching functions are invoked asynchronously with process execution, the behavior of some of the functions defined by this standard is unspecified if they are called from a signal-catching function. The following set of functions are reentrant with respect to signals (that is, applications can invoke them, without restriction, from signal-catching functions): _exit() access() alarm() chdir() chmod() chown() close() creat() dup2() dup() exec() fcntl() fork() fstat() getegid() geteuid() getgid() getgroups() getpgrp() getpid() getppid() getuid() kill() link() lseek() mkdir() mkfifo() open() pause() pipe() read() rename() rmdir() sem_post() setgid() setpgrp() setuid() sigaction() sigaddset() sigdelset() sigfillset() siginitset() sigismember() signal() sigpending() sigprocmask() sigsuspend() sleep() statx() tcdrain() tcflow() tcflush() tcgetattr() tcgetprgp() tcsendbreak() tcsetattr() tcsetpgrp() time() times() umask() uname() unlink() ustat() utime() wait2() wait() write() All other system calls should not be called from signal-catching functions since their behavior is undefined. RELATED INFORMATION
Functions: sigaction(2), sigblock(2), sigemptyset(3), siginterrupt(3), siglongjmp(3), sigpause(3), sigpending(2), sigprocmask(2), sigre- turn(2), sigset(3), sigsetjmp(3), sigstack(2), sigsuspend(2), sigvec(2), sigwait(3) delim off signal(4)
All times are GMT -4. The time now is 08:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy