Sponsored Content
Full Discussion: Reg trap signals
Top Forums Shell Programming and Scripting Reg trap signals Post 302855937 by Don Cragun on Saturday 21st of September 2013 04:11:40 PM
Old 09-21-2013
In recent versions of ksh, trap action DEBUG causes action to be executed just before each simple command the shell executes after that until the trap is removed. The DEBUG trap action is not inherited by subshells nor in functions. To get a better view of what is going on, you might want to try the following modification of your code:
Code:
#!/bin/ksh
let LIMIT=50
function check {
        printf "In check: %s\n" "${.sh.command}"
        if [[ LIMIT -eq 50 ]]
        then    print LIMIT OK
        else    print "LIMIT changed!"
        fi
} 
echo 1
trap check DEBUG
echo 2
print $LIMIT
if [ $LIMIT -gt 40 ]
then    echo 3t
else    echo 3f
fi
LIMIT=$((LIMIT + 30))
echo 4
trap - DEBUG
echo 5

Note that the compound variable .sh.command is the command that is about to be executed. The above script produces:
Code:
1
In check: echo 2
LIMIT OK
2
In check: print 50
LIMIT OK
50
In check: '[' 50 -gt 40 ']'
LIMIT OK
In check: echo 3t
LIMIT OK
3t
In check: LIMIT=80
LIMIT changed!
In check: echo 4
LIMIT changed!
4
In check: trap - DEBUG
LIMIT changed!
5


Last edited by Don Cragun; 09-21-2013 at 05:19 PM.. Reason: Fix typo
These 2 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Signals In HP-UX

does the way of handling, interrupting signals in HP-UX same as that of solaris. If there is difference than what it is.?:confused: (1 Reply)
Discussion started by: kapilv
1 Replies

2. UNIX for Advanced & Expert Users

how to trap signals.

hi!!, i wanna trap all Signal 10, 11, 15 generated by any process running on my server irrespective of the user and wanna write to a log file. Any ideas? Do this script need to be a root process?? :cool: (1 Reply)
Discussion started by: jyotipg
1 Replies

3. Shell Programming and Scripting

Building a better mouse trap, or How many lines of code does it take to trap a mouse?

Hello all, I'm hoping to get a little insight from some of the wily veterans amongst you. I've written a script to check for new outgoing files to our vendors located on our ssl server. It seems to be working ok, but the final question here, will be one of logic, and/or a better way to... (4 Replies)
Discussion started by: mph
4 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Signals...

(posted this in the scripting forum as well, but figured it should go here) So, what's going on is this: For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground process running, let's... (0 Replies)
Discussion started by: blind melon
0 Replies

6. Programming

Using Signals

How can use signals in a C program If i want a child program to signal it's parent program that it(child) program has completed the task that it was assigned.:confused: (2 Replies)
Discussion started by: kapilv
2 Replies

7. Shell Programming and Scripting

how trap the signals in shell scripting

Hi all, I have the c program that c program has to be in sleep mode. I want write a script the it should trap the signal from the c program. The signals are sighup,sigkill,sigterm,sigchld and then it has to go to sleep. If signal is sigchld it has to do to some function. My question is how to... (3 Replies)
Discussion started by: bhas85
3 Replies

8. 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

9. UNIX for Advanced & Expert Users

Help with Signals

Hi All, The problem statement is as below: Problem: A process (exe) is getting executed in background. The output of this process is getting logged in a file. After successfully running for some time the process gets terminated. In the log file following is present: ^M[7m Interrupt ^M[27m... (8 Replies)
Discussion started by: Praty.27
8 Replies

10. Shell Programming and Scripting

Help with trap and signals

I am having issues with trap not working inside a script. I am currently trying this on a Knoppix system V 5.1. What I would like to happen is when I press control c, a message gets echoed and the script is ended. For example: #! /bin/bash trap "echo CTRL c was pressed ; break" SIGINT... (11 Replies)
Discussion started by: Basherrr
11 Replies
MYSQLI_FETCH_LENGTHS(3) 						 1						   MYSQLI_FETCH_LENGTHS(3)

mysqli_result::$lengths - Returns the lengths of the columns of the current row in the result set

       Object oriented style

SYNOPSIS
array$mysqli_result->lengths () DESCRIPTION
Procedural style array mysqli_fetch_lengths (mysqli_result $result) The mysqli_fetch_lengths(3) function returns an array containing the lengths of every column of the current row within the result set. PARAMETERS
o $ result -Procedural style only: A result set identifier returned by mysqli_query(3), mysqli_store_result(3) or mysqli_use_result(3). RETURN VALUES
An array of integers representing the size of each column (not including any terminating null characters). FALSE if an error occurred. mysqli_fetch_lengths(3) is valid only for the current row of the result set. It returns FALSE if you call it before calling mysqli_fetch_row/array/object or after retrieving all rows in the result. EXAMPLES
Example #1 Object oriented style <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $query = "SELECT * from Country ORDER BY Code LIMIT 1"; if ($result = $mysqli->query($query)) { $row = $result->fetch_row(); /* display column lengths */ foreach ($result->lengths as $i => $val) { printf("Field %2d has Length %2d ", $i+1, $val); } $result->close(); } /* close connection */ $mysqli->close(); ?> Example #2 Procedural style <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $query = "SELECT * from Country ORDER BY Code LIMIT 1"; if ($result = mysqli_query($link, $query)) { $row = mysqli_fetch_row($result); /* display column lengths */ foreach (mysqli_fetch_lengths($result) as $i => $val) { printf("Field %2d has Length %2d ", $i+1, $val); } mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?> The above examples will output: Field 1 has Length 3 Field 2 has Length 5 Field 3 has Length 13 Field 4 has Length 9 Field 5 has Length 6 Field 6 has Length 1 Field 7 has Length 6 Field 8 has Length 4 Field 9 has Length 6 Field 10 has Length 6 Field 11 has Length 5 Field 12 has Length 44 Field 13 has Length 7 Field 14 has Length 3 Field 15 has Length 2 PHP Documentation Group MYSQLI_FETCH_LENGTHS(3)
All times are GMT -4. The time now is 08:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy