Home execvp appears to change pid of the process
Reply: 0

execvp appears to change pid of the process

user1557
1#
user1557 Published in May 22, 2018, 4:33 am

I created a program that does: 1. fork 2. from the son, create execvp with csh. The execvp csh runs a script a.sh that prints in infinite loop.

My problem is that I cant stop or kill the process from the father (using kill(SIGKILL,pid) from the father process didn't work). I think that the problem is in execvp. when I print the pid from the script(echo $BASHPID ) I get a different pid from the one that I get before the execvp. i know the pid after execvp is supposed to remain the same, but it seems like it doesn't.

here is the problematic code:

int ExeExternal(char* args[MAX_ARG], char* cmdString, int* fg_pid, char** L_Fg_Cmd){
        //int child_status;
        int pID;
        pID = fork();
        switch(pID) {
            case -1:        //error
                    perror("fork");
                    return 1;  
            case 0 :        // Child Process
                    setpgrp();
                    printf("son getpid() : %d",getpid());
                    fflush(stdout);
                    char* argument_for_cshs[5];
                    char* cmd="csh";               
                    argument_for_cshs[0]="csh";
                    argument_for_cshs[1]="-f";
                    argument_for_cshs[2]="-c";
                    argument_for_cshs[3]=cmdString;
                    argument_for_cshs[4]=NULL;    
                    execvp(argument_for_cshs[0],argument_for_cshs);       
                    //if return => there is a problem

any solution?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304298 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO