Define my own signal.

S

sanjeeb

Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.

With regards
Sanjeeb
 
J

Josef Moellers

sanjeeb said:
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.

That's an OS issue.

Signals and the handling of certain key combinations is done by the OS
(at least on Linux it is): the keyboard driver detects that Ctrl and C
are pressed together and sends signal SIGINT to the process.
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
sanjeeb
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.

I think you want some kind of setup of termio/termios (which see). If
your OS and/or CRTL provides such control, you should be able to make
a control char to generate a signal.

Hope this helps,
Ilya
 
S

sanjeeb

Ilya said:
[A complimentary Cc of this posting was sent to
sanjeeb
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.

I think you want some kind of setup of termio/termios (which see). If
your OS and/or CRTL provides such control, you should be able to make
a control char to generate a signal.

Hope this helps,
Ilya



I am using WINxp. Is there any wayout in XP.
With regards
sanjeeb
 
D

Dave

sanjeeb said:
Ilya said:
[A complimentary Cc of this posting was sent to
sanjeeb
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.

I think you want some kind of setup of termio/termios (which see). If
your OS and/or CRTL provides such control, you should be able to make
a control char to generate a signal.

Hope this helps,
Ilya



I am using WINxp. Is there any wayout in XP.
With regards
sanjeeb

You could probably do it using a global keyboard hook via the
SetWindowsHookEx function, but that would most likely need to be written in
C not Perl.
 
X

xhoster

sanjeeb said:
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .

You can't define your own signals, but there are existing signals you can
use for your own purposes.

$ perl -le '$SIG{USR1}=sub {die "USR1!"}; sleep ' &
[1] 25262

$ kill -USR1 25262
USR1! at -e line 1.

In SIG hash there is ctrl+C for INT .

In SIG hash there is INT for INT. That hitting your ctrl+C on your
keyboard causes the shell (or OS) to generate a INT signal is a completely
separate matter.
Suppose i want to define my own
signal which will trigerred when i pressed alt+s.

On linux, I can use Term::ReadKey to detect an alt+s (although it looks
no different than 'esc' followed by s). I could cause it to then
generate a signal for another process. I suppose you can do the same
thing on Windows.

Xho
 
C

Charles DeRykus

sanjeeb said:
Ilya said:
[A complimentary Cc of this posting was sent to
sanjeeb
Hi,
We know that there are predefined signals that a process catches when
some interrupt occurs. Can we define our own signals.If i am not
descriptive , i am giving an example .
In SIG hash there is ctrl+C for INT . Suppose i want to define my own
signal which will trigerred when i pressed alt+s. And after that i will
do my desired task through a handler.
I think you want some kind of setup of termio/termios (which see). If
your OS and/or CRTL provides such control, you should be able to make
a control char to generate a signal.
I am using WINxp. Is there any wayout in XP.

Ilya's suggestion may work but I know signal semantics are different...
in Win32 than Unix ... strangely different.

Unix: perl5.8.7 -le '$u1=0;$SIG{USR1} = sub {$u1=1}; kill USR1 => $$;
print $u1'
1

WinXP: 1st try:
perl5.8.8 -le "$u1=0;$SIG{USR1} = sub{$u1=1}; kill USR1 => $$;
print $u1"
Unrecognized signal name "USR1" ...

2nd try:
perl -le "$u1=0; $SIG{USR1} = sub{$u1=1}; kill '-USR1', $$
or die 'kill failed...'; print $u1"
0

Hm, the signal successfully fails... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top