Solved

Urgent! C Signal handling(UNIX)

Posted on 1998-04-19
7
288 Views
Last Modified: 2010-11-22
I am writing a C shell, and I want to launch a background
proc. How do I know when its terminateed?
And in general suppose I want to catch a signal. is there any way to do smth like that:

        IF (SOME SIGNAL)
           DO SMTH  
Thank you
0
Comment
Question by:danil082697
7 Comments
 
LVL 7

Expert Comment

by:busuka
ID: 1249840
I believe that signal( ) function is what you need.
 signal(2)

 NAME
      signal - specify what to do upon receipt of a signal

 SYNOPSIS
      #include <signal.h>

      void (*signal(int sig, void (*action)(int)))(int);

 DESCRIPTION
      signal() allows the calling process to choose one of three ways to
      handle the receipt of a specific signal.  sig specifies the signal and
      action specifies the choice.

I can put more if this is what you need.
0
 

Expert Comment

by:bing031398
ID: 1249841
The kernel will give you a SIGCLD or SIGCHLD when the shell's child teminates. Busuka is right. You can catch the signal using the signal function.
  Pass SIGCLD or SIGCHLD as the first parameter then pass the function to handle on the next parameter.
  Happy programming.
0
 
LVL 1

Author Comment

by:danil082697
ID: 1249842
well, suppose i need update several data structures, upon receiving a signal. But in signal(); i can only get an integer, then how do i get to the rest  of my structures.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Expert Comment

by:smithc
ID: 1249843
sounds like you need to set up some shared memory,,,,,
0
 

Accepted Solution

by:
bing031398 earned 200 total points
ID: 1249844
You have a lot of options:
  1. Make the structures global so the signal handler can change it.
  2. You can 'longjump' to a previously set location and set the data structures there.
  3. You can call an external function to do the update.
0
 
LVL 7

Expert Comment

by:busuka
ID: 1249845
danil, why you rejected my answer ? It was correct answer, but you
not wanted to hear explanations how to accomplish your task.
0
 

Expert Comment

by:upendra_swami
ID: 34194033
in my understanding, busuka is correct.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question