Hi Daniweb,
I'm making a shell-ish console for my Operating Systems class. Trying to get the shell to Terminate a process given a process name. Ever since I made the following addition to my code, this error is coming:
Program received signal SIGSEGV, Segmentation fault.In __gnu_cxx::__exchange_and_add(int volatile*, int) () ()
The code is here:
//...branches for other input commands
//branch for "terminate xxx" command
else if(cmdword.compare(commands[9]) == 0){
string id = " ";
//seperates and returns the id or name of the process
id = parseString(command);
//to check whether we have an id or a name
bool allnumb = true;
for(int i = 0; i<id.length(); i++){
if(id.at(i) < 48 || id.at(i) > 57){
allnumb = false;
break;
}
}
//if it is apparently an id
if(allnumb){
//function terminates the process with this id
//throws error if no such process. Is in working condition.
termprocess(id);
}
//if it is apparently a name
else{
int pindex = -1;
//find the first such pid that corresponds to the name given
for(int i = 0; i<Processes.size(); i++){
if(Processes.at(i).pname.compare(id) == 0){
pindex = i;
break;
}//endif
}//endfor
//if no such pid, then just send the id/name substring. termprocess will see if theres an id, and throw an error otherwise
if(pindex < 0){
termprocess(id);
}
//if there is such a pid, fetch it, convert it from DWORD to string
//end send it to termprocess
else{
char tpid[] = " ";
itoa(Processes.at(pindex).pid, tpid, 10);
string p_id(tpid);
termprocess(p_id);
}
}//endif
cout<<"hellow"<<endl;
}
cout<<"hellllllo"<<endl;
//error handling and execution-loop footer
Googling has told me that there is some pointer referencing issue going on here. I have tried to pinpoint it but am lost. The thing is, the code runs, the process terminates, the "cout<<hellow" also executes. However, as soon as it crosses the following brace, the error pops up, ie "helllllllo" will not print.
Please help me find the source of this issue, thanks