Sponsored Content
Top Forums Programming "No child processes" and waitpif Post 302296663 by Zipi on Wednesday 11th of March 2009 02:36:20 PM
Old 03-11-2009
"No child processes" and waitpif

Hi everybody,
i'm using a signal handler for the SIGCHLD signal.
Code:
void InstallNewSigChldHandler()
{     
    struct sigaction act;
    struct sigaction oldAct;
    act.sa_handler = CallWaitChildProcess;
 
    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_NOCLDSTOP;

    if (sigaction(SIGCHLD, &act, &oldAct) < 0) 
    {
        cout<<"error in sigaction";
    }
}

The actual signal handler code is:
Code:
void CallWaitChildProcess(int signo) 
{
    int status, child_val, errStatus;

    pid_t retPid;
    retPid=waitpid(g_ChildProcessPid, &status, WNOHANG);
    errStatus=errno;
    if (retPid < 0) 
    {
        printf("waitpid failed.Error cause:%s",strerror(errStatus));
        return;
    }

    if(retPid==0)
    {
        printf("waitpid returned 0");
        return;
    }

    if (WIFEXITED(status))                /* did child exit normally? */
    {
        child_val = WEXITSTATUS(status); /* get child's exit status */
        printf("process pid:%d --> terminated normally with status %d\n", g_ChildProcessPid,child_val);
    }
}

I'm doing this cause i want to run two external programs from my main application,and catch their return code.So,i have the g_ChildProcessPid variable which holds the pid for the external program.

I expected that every other child would cause waitpid to return 0,since i specify the WNOHANG flag,but in my code i have some calls to the "system" function that cause a "No child processes" error.

For example,in a function i do:
Code:
sprintf(command,"rm %s/%s",getenv("LOG_DIR"),"test.log");
system(command);

This causes waitpid to fail,with the following error:
Code:
waitpid failed.Error cause:No child processes

Why?
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. UNIX for Dummies Questions & Answers

Kill child processes, when parent is "bash"

Consider this simple command line bash -c 'echo $$ ; sleep 10000'This will print the newly created bash PID and sleep for a long time. If I go to another terminal and do something like ps -flax | grep leepI'll see something like 501 92418 91910 0 0:00.00 ttys000 0:00.00 bash -c echo $$... (5 Replies)
Discussion started by: teras
5 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

will child processes be created when executing "ps"?

Hi I'm trying to write some code to confirm there is only one running instance in memory like below: /usr/ucb/ps -auxww | egrep -v 'grep |vi |tail |more |cat ' | egrep ${SCRIPT_NAME} | egrep -v " \-h| \-help| \-v" But sometimes i found there is some child processes are are created as... (4 Replies)
Discussion started by: sleepy_11
4 Replies

5. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

6. Shell Programming and Scripting

What is the use of "finger" command & how to use it to kill the online processes ?

Hi there, I am eager to know what exactly is the use of "finger" command & how to use it to kill the online processes ? :b: (1 Reply)
Discussion started by: abhijitpaul0212
1 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
BSD_SIGNAL(P)						     POSIX Programmer's Manual						     BSD_SIGNAL(P)

NAME
bsd_signal - simplified signal facilities SYNOPSIS
#include <signal.h> void (*bsd_signal(int sig, void (*func)(int)))(int); DESCRIPTION
The bsd_signal() function provides a partially compatible interface for programs written to historical system interfaces (see APPLICATION USAGE). The function call bsd_signal(sig, func) shall be equivalent to the following: void (*bsd_signal(int sig, void (*func)(int)))(int) { struct sigaction act, oact; act.sa_handler = func; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, sig); if (sigaction(sig, &act, &oact) == -1) return(SIG_ERR); return(oact.sa_handler); } The handler function should be declared: void handler(int sig); where sig is the signal number. The behavior is undefined if func is a function that takes more than one argument, or an argument of a dif- ferent type. RETURN VALUE
Upon successful completion, bsd_signal() shall return the previous action for sig. Otherwise, SIG_ERR shall be returned and errno shall be set to indicate the error. ERRORS
Refer to sigaction() . The following sections are informative. EXAMPLES
None. APPLICATION USAGE
This function is a direct replacement for the BSD signal() function for simple applications that are installing a single-argument signal handler function. If a BSD signal handler function is being installed that expects more than one argument, the application has to be modi- fied to use sigaction(). The bsd_signal() function differs from signal() in that the SA_RESTART flag is set and the SA_RESETHAND is clear when bsd_signal() is used. The state of these flags is not specified for signal(). It is recommended that new applications use the sigaction() function. RATIONALE
None. FUTURE DIRECTIONS
None. SEE ALSO
sigaction() , sigaddset() , sigemptyset() , signal() , the Base Definitions volume of IEEE Std 1003.1-2001, <signal.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 BSD_SIGNAL(P)
All times are GMT -4. The time now is 03:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy