Shell job control

Posted by user1535672 on Stack Overflow See other posts from Stack Overflow or by user1535672
Published on 2012-11-11T03:46:45Z Indexed on 2012/11/11 5:01 UTC
Read the original article Hit count: 186

Filed under:

For my school project I am implementing a shell and I need help with job control. If we type a command, say cat &, then because of the & it should run in background, but it's not working. I have this code:

{
  int pid;  
  int status;  
  pid = fork();  
  if (pid == 0) {  
    fprintf(stderr, "Child Job pid = %d\n", getpid());  
    execvp(arg1, arg2);  
  } 
  pid=getpid();  
  fprintf(stderr, "Child Job pid is = %d\n", getpid());      
  waitpid(pid, &status, 0);  
}

© Stack Overflow or respective owner

Related posts about c