Reputation: 2783
I want processes to be blocked for a custom user signal and when the signal arrives it should wake up waiting process in shell script?need just steps coding i can take care of?
Upvotes: 2
Views: 378
Reputation: 755016
If the signal you wish to send is signal number 17, then you might use:
trap ":" 17
sleep 1000000
trap 17
# ...what you want to happen after the signal is received...
The first trap
command will execute the quoted command (:
) when the signal is received. The :
command does nothing. However, you can't use trap "" 17
as that means 'ignore signal 17', which is the opposite of what you want.
The sleep 1000000
is a way to do nothing for a long time without using up CPU resource.
The second trap
cancels the signal handling for signal 17, reinstating the default behaviour.
After that, you can put whatever code you want executed once the signal is received.
Instead of using sleep
, you might prefer to create and use a program, pause
, which waits indefinitely (rather than risk the sleep
waking up before the signal is received). You could use this trivial program:
#include <unistd.h>
int main(void)
{
pause();
return(0);
}
As a point of detail, the return won't usually be executed; the signal will usually force the program to terminate before pause()
returns with errno == EINTR
.
Upvotes: 1
Reputation: 813
It's not 100% clear what you're trying to do, but it sounds like you basically want a shell-scrip "keylogger" to listen in the background and take action based on things. If I'm correct, I'm not going to ask why... if I'm not I apologise ;-)
If you want to go hardcore you could learn about the /dev/input/event* files in the filesystem and how to follow them. Alternatively you could look at this tutorial for creating a keylogger and loggin: http://www.slideshare.net/rmorrill/creating-a-keystroke-logger-in-unix-shell-scripting
Finally, if you really do just want to install and go you could try installing this: http://www.justhackitnow.com/2012/03/keylogger-for-linux.html
Upvotes: 0