Changeset 2955 in Sophya for trunk/SophyaLib/SysTools/commander.cc
- Timestamp:
- May 29, 2006, 7:27:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/commander.cc
r2943 r2955 443 443 static Commander* cur_commander = NULL; 444 444 /* --Methode-- */ 445 //! Default constructor. Initializes variable list and copies \c history.pic to \c hisold.pic 446 Commander::Commander() 445 /*! 446 \brief Constructor. Initializes variable list and copies \c history.pic to \c hisold.pic 447 if \b fgsigstop == true , calls ZThread::ActivateExitOnSignal() 448 */ 449 Commander::Commander(bool fgsigzt) 447 450 { 448 451 system("cp history.pic hisold.pic"); … … 512 515 usage += " > thrlist # List of command execution threads (& as the last character) \n"; 513 516 usage += " > clearthrlist # Removes finished threads from the list \n"; 514 usage += " > stopthr Id # Try to stop a given thread (ThrId=id) sending SIGUSR1 \n"; 517 usage += " > killthr Id # Try to stop a given thread (ThrId=id) by sending SIGUSR1 \n"; 518 usage += " > cancelthr Id # Try to cancel a given thread (ThrId=id) \n"; 515 519 usage += " > waitthr # Waits until all active threads have finished (join()) \n"; 516 520 usage += " > exec filename # Execute commands from file \n"; … … 577 581 AddInterpreter(this); 578 582 curcmdi = this; 583 if (fgsigzt) ZThread::ActivateExitOnSignal(SIGUSR1); 579 584 } 580 585 … … 1878 1883 return(0); 1879 1884 } 1880 else if (kw == "stopthr") { 1881 if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: stopthr thrid" << endl; return(0); } 1885 else if ( (kw == "killthr") || (kw == "cancelthr") ) { 1886 if (tokens.size() < 1) { 1887 cout << "Commander::Interpret() Usage: killthr/cancelthr thrid" << endl; 1888 return(0); 1889 } 1882 1890 uint_8 id = atol(tokens[0].c_str()); 1883 StopThr(id); 1891 bool fgkill = false; 1892 if (kw == "killthr") fgkill = true; 1893 StopThr(id, fgkill); 1884 1894 return (0); 1885 1895 } … … 2026 2036 void Commander::ListThreads() 2027 2037 { 2028 cout << "--- - Commander::ListThreads() List of separateexecution threads NThread="2029 << CmdThrExeList.size() << " --- --" << endl;2038 cout << "--- Commander::ListThreads()- command execution threads NThread=" 2039 << CmdThrExeList.size() << " ---" << endl; 2030 2040 for(list<CommandExeThr *>::iterator tit = CmdThrExeList.begin(); 2031 2041 tit != CmdThrExeList.end(); tit++) { 2032 2042 cout << "Id=" << (*tit)->Id(); 2033 if ( (*tit)->IfDone() ) cout << " Finished , Rc= " << (*tit)->getRC(); 2034 else cout << " Executing"; 2035 cout << " (Cmd= " << (*tit)->Keyword() << " " << (*tit)->Tokens() << " )" << endl; 2036 } 2037 } 2038 /* --Methode-- */ 2039 void Commander::StopThr(uint_8 id) 2043 if ( (*tit)->IfRunning() ) cout << " Executing"; 2044 else if ( (*tit)->IfDone() ) cout << " Finished , Rc= " << (*tit)->getRC(); 2045 else cout << " Stopped/Canceled"; 2046 cout << " (Cmd= " << (*tit)->Keyword() << " " << (*tit)->Tokens().substr(0,35); 2047 if ((*tit)->Tokens().length() > 35) cout << "... )" << endl; 2048 else cout << " )" << endl; 2049 } 2050 } 2051 /* --Methode-- */ 2052 void Commander::StopThr(uint_8 id, bool fgkill) 2040 2053 { 2041 2054 for(list<CommandExeThr *>::iterator tit = CmdThrExeList.begin(); 2042 2055 tit != CmdThrExeList.end(); tit++) { 2043 if ( ((*tit)->Id() == id) && !((*tit)->IfDone()) ) { 2044 (*tit)->kill(SIGUSR1); 2045 cout << "Commander::StopThr() Send signal SIGUSR1 to Thread Id= " << id << endl; 2056 if ( ((*tit)->Id() == id) && ((*tit)->IfRunning()) ) { 2057 if (fgkill) { 2058 (*tit)->kill(SIGUSR1); 2059 cout << "Commander::StopThr() Send signal SIGUSR1 to Thread Id= " << id << endl; 2060 } 2061 else { 2062 (*tit)->cancel(); 2063 cout << "Commander::StopThr() Canceling Thread Id= " << id << endl; 2064 } 2046 2065 return; 2047 2066 } … … 2055 2074 cout << "---- Commander::CleanThrList() Cleaning thrlist ----- \n"; 2056 2075 list<CommandExeThr *> thrcopie; 2076 int ncl = 0; 2057 2077 for(list<CommandExeThr *>::iterator tit = CmdThrExeList.begin(); 2058 2078 tit != CmdThrExeList.end(); tit++) { 2059 if ( ( *tit)->IfDone() ) {2079 if ( ((*tit)->IfEnded() || (*tit)->IfStopped()) && (ncl < 3) ) { 2060 2080 cout << " Thread Id= " << (*tit)->Id() << " rc= " << (*tit)->getRC() << " Cleaned" << endl; 2061 2081 delete (*tit); 2082 ncl++; 2062 2083 } 2063 2084 else thrcopie.push_back((*tit));
Note:
See TracChangeset
for help on using the changeset viewer.