Writing a shell in C for linux, exec for one certain process is infinitely looping -


this relevant snippet of code:

if(!strcmp(args[0],"run")){                 pid_t pid = fork();                 if(pid == 0){                   execvp(args[1], args);                   fprintf(stdout, "process not found in directory\n");                   kill((int)getpid(), sigkill);                 }                 else{                     if(pid < 0)                         exit(1);                      fprintf(stdout, "pid of process = %d\n", pid);                     int success = waitpid(pid, &childexitstatus, wuntraced | wcontinued);                      if(success == -1)                         exit(exit_failure);                 }              } 

now when run process libre office math, open 1 instance of it. however, when try open xterm using code, continue exec on , over, creating many instances of xterm before interrupt , exit. don't see loops cause happen. insight why be?

the execvp() call incorrect because passes additional argument "run" @ start. when executing xterm in manner, effect similar xterm xterm , has xterm use xterm shell. new xterm inherits shell environment variable causes start xterm, until limits exhausted.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -