• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Urgent! C Signal handling(UNIX)

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
danil082697
Asked:
danil082697
1 Solution
 
busukaCommented:
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
 
bing031398Commented:
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
 
danil082697Author Commented:
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
smithcCommented:
sounds like you need to set up some shared memory,,,,,
0
 
bing031398Commented:
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
 
busukaCommented:
danil, why you rejected my answer ? It was correct answer, but you
not wanted to hear explanations how to accomplish your task.
0
 
upendra_swamiCommented:
in my understanding, busuka is correct.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Managing Security & Risk at the Speed of Business

Gartner Research VP, Neil McDonald & AlgoSec CTO, Prof. Avishai Wool, discuss the business-driven approach to automated security policy management, its benefits and how to align security policy management with business processes to address today's security challenges.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now