Sponsored Content
Top Forums Programming catching a signal from child process Post 302191400 by ramen_noodle on Friday 2nd of May 2008 12:08:50 PM
Old 05-02-2008
Code:
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>

void childexit(int signal_num) {
int retval, nval;
char buf[256];
                 bzero(buf,256);
                 nval =   waitpid(0,&retval,WNOHANG);  
                 sprintf(buf,"Waited on child %d which exited with code = %d\n",nval,retval);       
                  write(STDOUT_FILENO,buf,256);
}

int main(void) {

                    signal(SIGCHLD,childexit);
                    /*rest of code*/
}

 

10 More Discussions You Might Find Interesting

1. Programming

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... (7 Replies)
Discussion started by: joseph_ng
7 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Sending signal from child to parent process!

Hi All, I facing a problem in handling signals between parent process communication. I am trying to send a signal(SIGINT) from child to parent. I am using kill function to do so and I am trying to read the signal using sigaction(). But the program is ending abruptly and I am not able to figure out... (4 Replies)
Discussion started by: vkn_1985
4 Replies

4. Shell Programming and Scripting

Catching SIG of running process with bash

Hello all! I'm writing a script that will catch when an outside process crashes (SIGHUP, right?) without having to loop into infinity. With that in mind, I came across the trap utility and thought if could be used to monitor another process other than it's own. But from what I've read, I'm... (1 Reply)
Discussion started by: mashiox
1 Replies

5. Programming

how can i make that a process child send a signal?

I'm trying to do a program that makes activate an signal (SINGALARM) when the next child of a son appears but this not works. I have to caught the next child o the other (pid), to send a singnal which inform a menssage. It's anything worng in the code? thanks. the code: #include... (2 Replies)
Discussion started by: marmaster
2 Replies

6. Programming

Parent,child wait,signal

Hello. I want to make a child do some stuff,wait,then the parent does some stuff and then child does some stuff and waits again.I have made the following but it does not work.Can anybody help me? pid1 = fork(); if (pid1 == -1) { perror("Can't create child\n"); ... (18 Replies)
Discussion started by: Cuervo
18 Replies

7. Programming

Parent process starts before the child using signal, in C

Hi, i want that the parent process start before the child, this code doesn't work, if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf; else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies

8. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

9. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

10. 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
acps_spi(3)						     Library Functions Manual						       acps_spi(3)

NAME
acps_spi: acpm_getenvattrs(), acpm_getobj(), acpm_getobjattrs(), acpm_getop(), acpm_getopattrs(), acpm_getsubattrs(), acpm_getsubcreds(), acpm_getsubid() - ACPS Service Provider Interface SYNOPSIS
[flag]... file... [library]... DESCRIPTION
The ACPS Service Provider Interface makes it possible to define a custom module that responds to access control requests. This module is typically written either to enforce a custom policy, or to interface to another system that defines such a policy. By creating this module and inserting an appropriate entry into the file, all access control requests made by applications that support the Access Control Policy Switch will automatically be routed to the module, without modifying the applications. The service provider (module) interface is primarily composed of a well-defined routine that each module must provide and a set of helper routines provided by the switch to encode and decode information into the opaque handle. The single interface provided by each module is defined as follows: The handle contains all of the request information. The argv argument contains an array of elements, each representing an argument speci- fied in the ACPS configuration file entry for the module (see below). The module return values match exactly the API return values with the option of an additional value indicating that no access information is available for the given request In order for the module to retrieve information from the handle about the access control request, the switch provides the following set of helper routines to extract the desired information, described in Note that these routines are very similar to the API routines except that the multi-value attributes are returned as a linked list rather than requiring individual routines. The practical reason for this is that it allows greater flexibility in manipulating the attribute data based on the needs of the module. In the same way that an application can retrieve the credential requested by a module, (see acps_api(3)), the module has the following interface to encode this information into the handle: A module would typically use this in the event that the application did not present the required credential. It is expected that the application will add the necessary information and repeat the call to RETURN VALUE
The values returned by the ACPS SPI (as well as the ACPS API) are defined in acps(3). EXAMPLES
The following example illustrates a sample policy module that enforces the policy: "users Ron, Ren, and Bill may read or write the password object" #include <acps_spi.h> #include <stdio.h> extern int acpm_checkauth(acp_handle_t h, int argc, const char **argv) { char *user; char *operation; char *object; char *buf; int retval; // get the user if((retval = acpm_getsubid(h, buf, &user)) != ACPS_SUCCESS) return retval; if(strcmp(buf, ACPS_ID_NAME) != 0) // type validation return ACPS_GEN_ERROR; // get the operation if((retval=acpm_getop(h, buf, &operation)) != ACPS_SUCCESS) return retval; if(strcmp(buf, ACPS_OP_DOTHEIRARCHICAL) != 0) return ACPS_GEN_ERROR; // get the object if((retval = acpm_getobj(h, buf, &object)) != ACPS_SUCCESS) return retval; if(strcmp(buf, ACPS_OBJ_GENERIC) != 0) return ACPS_GEN_ERROR; // evaluate primitives against policy if( ( (strcmp(user, "Ron") == 0) || (strcmp(user, "Ren") == 0) || (strcmp(user, "Bill") == 0)) &&( (strcmp(operation, "read") == 0) || (strcmp(operation, "write") == 0)) &&(strcmp(object, "password"))) { return ACPS_ALLOW; } else { return ACPS_DENY; } } SEE ALSO
acps(3), acps_api(3). acps_spi(3)
All times are GMT -4. The time now is 09:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy