I'm creating a program which is like an "shell interpreter" but in C, in the main program called "Bash" if I write in command line "change NAME" it creates a fork and executes an execlp to call a program "cd" who should change my current directory
if(strcmp(argv[0], "change"){
     pid = fork();
     if (pid == 0){
         execlp("./cd", "./cd", argv[1], NULL);
     }
It works perfectly, it runs my program cd and in theory changes but after the program end it turns back to elder directory
#include <unistd.h>
#include <stdio.h>
#include <limits.h> 
#include <string.h>
#include <stdlib.h>
//PWD
int main(int argc, char *argv[]) {
    char diratual[90], dir[90], barra[90] = "/";
    char *local[argc];
    local[0] = argv[1];
    getcwd(diratual, sizeof(diratual));
    
    strncat(diratual, barra, sizeof(barra));
    strncat(diratual,local[0],sizeof(local[0]));
    
    chdir(diratual);
    system("pwd");
    
    }
I use string to create the full path destination, I test the program after whole execution and it gives me back the path I've entered, but when it ends if I type "pwd" in my main program it shows the older. example:
I'm in /home/user/Documents
And want to enter in /home/user/Documents/Test
So I type 'change Test'
it receives 'Test' as arg[1] and align with program internal strings to create a string called:
string = "/home/user/Documents/Test"
After that I use - chdir(string);
So in the end the system("pwd"); returns the expected "/home/user/Documents/Test'
but when the program ends it returns to the main program
and when I type pwd in my main program it shows '/home/user/Documents
How can I solve this? to enter and stay in the directory typed?
 
    