LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-10-2006, 03:45 AM   #1
basak
Member
 
Registered: Jul 2006
Posts: 41

Rep: Reputation: 15
evoke a signal


HiIs it possible to send a signal to other programs when something happens in a shell script.For example we can "echo" something to the screen and the user understands that the event has occured.But I need some background running programmes (other commands etc.) to be aware of that by getting a signal when the thing happens,(so that their execution process may have some kind of branching etc.)Thank u
 
Old 08-10-2006, 07:18 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
There are many ways to do that (sockets, RPC (remote procedure calls), signal handling).
What kind of programs are you talking about?
ie will they always run on Linux? On the same machine or multiple machines?

Example: you can use the "kill" command in your shell script to send specific signals to the program.
Typically, such signals are used to either stop (SIGKILL) or suspend (SIGSTOP, etc) a program or to make it reread it's configuration file (SIGHUP is often used for this).
Many of these signals can be "caught" and handled by the program (or, if you don't want to modify the code, by the shell script wrapper around the program).

Sockets are often used for network communication.

Another option is to use a named FIFO pipe. They look like ordinary files, so you can easily write/read from them, but they operate like the pipes you put between commands (one program uses the pipe for reading, the other for writing typically).
 
Old 08-10-2006, 08:31 AM   #3
basak
Member
 
Registered: Jul 2006
Posts: 41

Original Poster
Rep: Reputation: 15
Thank u for your help timmekeActually the thing that I am trying to learn is that;

Lets say while command1 is executing, it assigns another procedure to the background ,namely command2.While command2 keeps executing ,it should receive a signal from command1 to do smth.This can be achieved by command1 writing to a file when the thing happens and command2 regularly checking whether the file is written.But I don't want that kind of "pooling",instead an "interrupt" sent from command1 will be much more efficient.I intend to make the communication between 2 synchronously running commands.?????????????????
 
Old 08-10-2006, 08:41 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
As I said, there are many ways to do that.
I would stick to signals, but that's just me.
Check out the man pages of 'kill' and your shell (if it's Bash, search for the 'trap' command).

Using a fifo pipe may also require some kind of "polling" from program2 (ie regularly try reading from the pipe).

The others (sockets and stuff) is more for networking, so I don't recommend those for your situation.

What programming language where the programs written in? Are they both shell scripts?
 
Old 08-10-2006, 09:10 AM   #5
basak
Member
 
Registered: Jul 2006
Posts: 41

Original Poster
Rep: Reputation: 15
Yes ,they are both (bash) shell scripts for now.Assuming that everything will run in Linux environment,it would be better to be able to send the signal to any program which calls the command1.Thanks again
 
Old 08-11-2006, 01:47 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Don't get me wrong. On Linux (or Unix, for that matter), you can send signals to any program you like (use the 'kill' command to do that). The only problem will be to make program2 catch and respond to the signal the way you like it, rather than the default way (which is typically to stop program2's execution completely).

Anyway, I'd recommend taking a look at 'kill' and 'trap' (in bash man page) commands for starters.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
squid stops due to signal 6 and signal 25 simplyrahul Linux - Software 3 05-28-2011 01:05 AM
Evoke program from html in Konqueror Darkfalz Linux - Software 2 11-17-2005 08:52 AM
Clicking an URL to evoke a browser satimis Linux - General 2 03-12-2005 05:53 AM
Signal 6: Unknown Signal <=> Error with MAYA4.X under Linux SOLVED!!!! Faeroon Linux - Software 9 05-09-2003 01:57 PM
Signal: 6 (Unknown Signal) - Problems running a program Faeroon Linux - Software 86 01-14-2003 12:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration