How to trap repeated Control-C?

How to trap repeated Control-C?

Post by Michael Wa » Mon, 18 Jan 1999 04:00:00



If I have
trap 'some_jobs; exit 1' 1 2 3 15
Then it will trap Control-C (signal numver 2?) and
perform "some_jobs" and exit.

However while shell script perform "some_jobs", it received
repeated Control-C, what is going to happen? How can I
ignore the repeated Control-C and finish the jobs. Thanks.
--
unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog

 
 
 

How to trap repeated Control-C?

Post by Marvin Wolftha » Tue, 19 Jan 1999 04:00:00


some_jobs()
{
    trap '' 2
    ...
    ...

}

> If I have
> trap 'some_jobs; exit 1' 1 2 3 15
> Then it will trap Control-C (signal numver 2?) and
> perform "some_jobs" and exit.

> However while shell script perform "some_jobs", it received
> repeated Control-C, what is going to happen? How can I
> ignore the repeated Control-C and finish the jobs. Thanks.
> --
> unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
> submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog


--
Marvin Wolfthal
Technical Director
FSJ, Inc. (N.A)


 
 
 

How to trap repeated Control-C?

Post by oscar morale » Wed, 20 Jan 1999 04:00:00


Hello Michael:

If I have not misunderstood your question you are trying to catch "ctrl-c" and
"ctrl-z" signals. Usually the system call "signal" was used but this is the old
method for
catching signals. Now is best-used the system call sigaction to perform this
operation.

Here is the code of a small program catching the signal SIGINT (ctrl-c). The
program
counts down from 10 to 1 and every time the ctrl-c is pressed, the signal is
catched and
and a warning message is printed out. Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

main () {
  void sigint_handler (int signo);

  int i;
  struct sigaction sa;
  char s[100];
  sigset_t mask;

  sigemptyset(&mask);
  sa.sa_handler = sigint_handler;
  sa.sa_mask = mask;
  sa.sa_flags = SA_RESTART;
  sigaction(SIGINT, &sa, NULL);  // you should error-check this line.

  for (i = 10; i >= 1;i--) {
     printf("%d\n", i);
     sleep(1);
  }

Quote:}

void sigint_handler(int signo) {
  printf("catching SIGINT signal\n");

Quote:}

This code has been compiled with "cc -o catch catch.c" and executed in Sun
Solaris 5.5.1
Take a look at man pages for "sigaction" and "sigemtpyset" for more details.

Best regards,

Oscar Morales.


> If I have
> trap 'some_jobs; exit 1' 1 2 3 15
> Then it will trap Control-C (signal numver 2?) and
> perform "some_jobs" and exit.

> However while shell script perform "some_jobs", it received
> repeated Control-C, what is going to happen? How can I
> ignore the repeated Control-C and finish the jobs. Thanks.
> --
> unix programs: niftp (non-interactive recursive ftp), hide (hide command args),
> submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog


 
 
 

How to trap repeated Control-C?

Post by Lawson Hans » Sat, 23 Jan 1999 04:00:00



>If I have
>trap 'some_jobs; exit 1' 1 2 3 15
>Then it will trap Control-C (signal numver 2?) and
>perform "some_jobs" and exit.
>However while shell script perform "some_jobs", it received
>repeated Control-C, what is going to happen? How can I
>ignore the repeated Control-C and finish the jobs. Thanks.

Assuming that "some_jobs" is a function, you could try
adding another trap statement inside the function to
ignore any more control-C characters, e.g.:

some_jobs ( )
{
    trap "" 1 2 3 15

    # then do whatever ...

    # and perhaps exit from here ...
    exit 1

Quote:}

I hope that may help.

Best regards,

Lawson Hanson

 
 
 

1. Trap Control-C key in unix

I want to trap a telnet user from using Control-C key, so that
they cannot terminate or bypass certain process.

For example, when a user telnet to the server, After he/she logins,
he/she has to change his/her password. After that, he/she will be force
to logout.

How can I prevent he/she by pass that process : changing password?
He/she may press Control-C key to bypass that process. So how can I
implement this in user's .profile?

FYI I use Solaris 7 with bourne shell.

Sent via Deja.com
http://www.deja.com/

2. please help! re: sed & null characters

3. Trap Control-C key in Solaris

4. iBCS 2.1 and Kernel 2.4.x

5. how do I dec repeat delay & inc repeat rate

6. Added missing dependencies on CRYPTO_HMAC

7. HELP! Trapping control Z in menu script

8. Log Print Jobs

9. trapping "control C"

10. MMDF & uucp Mail repeating and repeating and .............

11. Trap Loss of Control Terminal

12. Trapping Control C

13. Trapping Control Characters [HELP!!]