Catching signal and piping


 
Thread Tools Search this Thread
Top Forums Programming Catching signal and piping
# 1  
Old 11-12-2005
Catching signal and piping

Hi,

Recently I was reading some c coding by some colleagues and I noticed that the above trend. They will create a pipe for the process then they will use the standard signal handler to capture a particular signal and write that signal to the pipe. On the other end, the process will read the pipe and retreive the signal.
Is it enough to simply use the signal handler and do a switch case. Why do they have to create a pipe?

I am sorry if this is a newbie question. Smilie
# 2  
Old 11-13-2005
it looks like this's a signal forwarding. however, since not all signals can be caught (such as kill), all signals won't be forwarded.

Quote:
Is it enough to simply use the signal handler and do a switch case.
for what?
# 3  
Old 11-13-2005
I mean is it necessary to do a piping or can I just do it the normal way? What is the purposes or advantages of doing a piping in this case? Please give me whatever advice you can provide.

Sorry, I am pretty newbie to these stuffs.
# 4  
Old 11-14-2005
I have never heard of handling signals in this manner. It sounds like a silly technique to me. Why not ask the authors why they did that?
# 5  
Old 11-14-2005
I run through my system's source codes and I notice that this is often done for application programs or process that uses motif but it is also used for some other processes that perform serial port communication. Recently, I have written a motif application for a GSM server and I am also using their piping methods but now I am questioning the purpose/wisdom of doing it.
Its basically a 5 steps procedure
1)Do the standard signal declarations
2)Open a pipe
3)Create a signal handler for a particular signal eg SigUSR1
4)If the handler is provoked, write something(can be anything) into the pipe, chain the old handlers
5)Read the pipe and if there is something in there, do something, mostly cross-server processes.

Isn't it easier to use the standard signal handlers and do a case statement to decide what to do for each received signals?

Is it possible that the original authors wanted to avoid too much handling codes for different signals so they decided to simply create a pipe for single signal handling? I believe they are doing this for some good reasons because they are doing this for almost all the processes. I may sounds a bit stubborn but I am really very curious and very interested to get an answer for this.

I have tried to ask one of them(there are not many left) but he could not give me a good answer Smilie
# 6  
Old 11-14-2005
You seem to be convinced this is a brilliant technique and great insights await anyone who understands it. That might be true. But maybe they just didn't know any better.

Quote:
Originally Posted by joseph_ng
I have tried to ask one of them(there are not many left) but he could not give me a good answer Smilie
I can't say that I'm surprised.
# 7  
Old 11-14-2005
Anyway, thanks for the prompt reply and advice. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

BSM not catching creat64

Solaris 9 system: I'm trying to get BSM to record to the point where additional files being put into /etc/opt/csw/sudoers.d will be recorded but thus far all I'm able to get are when files are deleted (via unlink). I've even tried auditing based on the "all" audit flag temporarily (thinking I... (2 Replies)
Discussion started by: thmnetwork
2 Replies

2. Shell Programming and Scripting

Catching error in sftp

Hi All Experts, I have a script which logs to the server via sftp connection with below code :- user_name@sftp_server.com and the connection is going smooth. My requirement is to place file in sftp_server in some path. and if path doesn't exist or the file is not put successfully I... (3 Replies)
Discussion started by: punitsoneji
3 Replies

3. Shell Programming and Scripting

Quiting running process without catching TRAP signal

Hi, I would like to ask, if is it possible to quit running loop in the script any other way than catching the trap signal. Ctrl-C ends only current running instance of process but not whole script. Any clues? (3 Replies)
Discussion started by: smoofy
3 Replies

4. Shell Programming and Scripting

Catching the termination of one script

Hi I have a Shell script that needs to execute a command at the End of the excursion of other script And I cant get a handel On the trap command. And that is if the trap command Is the proper way to go this is a extract of the script MYHOST=`hostname| cut -d. -f1` echo $MYHOST ... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

5. Shell Programming and Scripting

Catching errors

Hi, I'm writing a scheduling script which will co-ordinate the launching of scripts. This script is scheduling based on an input file, and launches the appropriate scripts at the right times. The only issue I'm having is: - if a script dies, or even has a syntax error, I want to catch... (1 Reply)
Discussion started by: GoldenEye4ever
1 Replies

6. Programming

Signal catching

Hi! I want to catch all signals that my program receives print their name and then execute the default handler. Can you help me on that? I've tried the following code: #include <stdio.h> #include <unistd.h> #include <signal.h> void (*hnd)(int i); char signals = { "SIGHUP",... (7 Replies)
Discussion started by: dark_knight
7 Replies

7. Programming

catching a signal from child process

i am creating children processes using fork system call every child i create goes to sleep for random time. when child stops running how can i catch his signal and turminate the child (2 Replies)
Discussion started by: emil2006
2 Replies

8. Shell Programming and Scripting

catching some errors

I need to find a way to keep a running tally of how many times events or actions occur. Say if a user is prompted to make inputs of 1 or 2, I want it to keep track of how many times 1 was entered, and how many times 2 was entered. Thanks for your help (5 Replies)
Discussion started by: bebop1111116
5 Replies

9. UNIX for Dummies Questions & Answers

catching interrupts

hey i have been facing a problem,can you tell me if we can catch ctrl d in unix i have tried and sucessfully catched and disabled ctrl-c and ctrl -z but am not sure if we can do the same for CTRL-D, so got any clue mail on he forum or ...i mean c programming in Unix thats what i am working on (1 Reply)
Discussion started by: toughguy2handle
1 Replies
Login or Register to Ask a Question