sigchld - Unix

This is a discussion on sigchld - Unix ; In following code when I catching SIGCHLD, it is not returning to parent. it keeps on running child process. In follwing it will not display menu again but if I don't catch SIGCHLD it works properly. int main() { int ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: sigchld

  1. sigchld

    In following code when I catching SIGCHLD, it is not returning to
    parent. it keeps on running child process. In follwing it will not
    display menu again but if I don't catch SIGCHLD it works properly.


    int main()
    {
    int c;
    char file[100];
    void sig_child();
    void list();
    void read1(char *);
    struct sigaction s,sc;
    s.sa_handler=SIG_IGN;
    sc.sa_handler=sig_child;
    sigemptyset(&s.sa_mask);
    sigemptyset(&sc.sa_mask);


    s.sa_flags=0;
    sc.sa_flags=0;


    if(sigaction(SIGINT,&s,0)<0)
    perror("sigaction_int");
    if(sigaction(SIGCLD,&sc,0)<0)
    perror("sigaction_cld");


    while(1)
    {


    printf("\n\tMENU\n");
    printf("1)List files\n2)Read file\n\n3)Exit\n");
    scanf("%d",&c);
    switch(c)
    {
    case 1: list();
    break;
    case 2: printf("Enter the file to be read");
    scanf("%s",file);
    read1(file);
    printf("parent");
    break;
    case 3: exit(0);
    default: break;
    }



    }
    }


    void list()
    {
    char path[100];
    DIR *dp;
    struct dirent *dirp;
    struct stat buf;
    printf("Enter the path\n");
    scanf("%s",path);
    dp=opendir(path);
    while((dirp= readdir(dp))!=NULL)
    {
    if(strcmp(dirp->d_name,".")==0 || strcmp(dirp->d_name,"..")==0)
    continue;

    lstat(dirp->d_name,&buf);
    if(S_ISREG(buf.st_mode))
    printf("%s\n",dirp->d_name);
    }
    closedir(dp);



    }


    void read1(char *rfile)

    {
    pid_t pid;


    if((pid=vfork())<0)
    perror("fork");
    else if(pid==0)
    {
    if((execl("/usr/bin/od","/usr/bin/od","-c",rfile,
    (char*)NULL))<0)
    perror("exec");
    _exit(0);
    }
    return;



    }


    void sig_child()
    {

    pid_t pid;
    int status,child_val;
    printf("child catch");


    if((pid=wait(&status))<0)
    {
    perror("pid");
    printf("pid=%d\n",pid);
    return;
    }
    if(WIFEXITED(status))
    {
    child_val=WEXITSTATUS(status);
    printf("child exited normally %d",child_val);


  2. Re: sigchld

    In article <1132253511.700353.185110@g43g2000cwa.googlegroups. com>,
    "friend.05@gmail.com" wrote:

    > In following code when I catching SIGCHLD, it is not returning to
    > parent. it keeps on running child process. In follwing it will not
    > display menu again but if I don't catch SIGCHLD it works properly.


    You asked the same question yesterday in comp.unix.programmer. Why do
    you think a non-programming group would be a better place to ask the
    question now?

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***

  3. Re: sigchld

    hey,
    thanks for your help. i got the problem.


  4. Re: sigchld

    friend.05@gmail.com wrote:
    > hey,
    > thanks for your help. i got the problem.
    >

    what help, what problem?

+ Reply to Thread