Help with a small shell program

My course is called operating systems and I have a HUGE project due at the end of the semester. But in order to get started on the right foot, I just wanted to get all my basics right. So here's some code that creates a process. How do I let the user create processes and then be able to terminate all process by a command (say terminate)?

#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

int main()
{
pid_t pid, pid1,
pid = fork();

if(pid < 0){
fprintf(stderr, "Fork Failed");
return 1;
}

else if (pid == 0){ //signifies the child process
pid1 = getpid();
printf("child: pid = %d",pid);
printf("child: pid1 = %d",pid1);
}

else{ //signifies the parent process
pid1 = getpaid();
printf("parent: pid = %d",pid);
printf("parent: pid1 = %d",pid1);
wait(NULL);
}

return 0;

}
[code] "Please use code tags" [/code]
Send a signal kill(child_pid, SIGKILL);
If you are at the command-line, you can use ps command to get the pid and then do a kill -9 <pid> Wrap all those commands inside a terminate.sh and then all you need to do is terminate.sh to execute it.

Above uses the Unix scripting solution which btw is used very often by systems administrator as it is fast and does not require compilation of a C/C++ program to achieve the same objective.
Topic archived. No new replies allowed.