Solved

Urgent! C Signal handling(UNIX)

Posted on 1998-04-19
7
286 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:smithc
Comment Utility
sounds like you need to set up some shared memory,,,,,
0
 

Accepted Solution

by:
bing031398 earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
in my understanding, busuka is correct.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now