pid_t sysWaitPid(pid_t filter, void *waitStatus, int options) { //check if any of the current children that match the filter are status=PROCSTATE_FINISHED //if so return pid_t ret = 0; bool exist = false; thread_t curThread = getCurrentThread(); struct Process *proc = curThread->process; acquireSpinlock(&curThread->lock); //lock curThread early to prevent child exit during execution of this function acquireSpinlock(&proc->lock); struct Process *child = proc->children; while (child) { acquireSpinlock(&child->lock); if (checkFilter(filter, child)) { exist = true; if (child->state == PROCSTATE_FINISHED) { releaseSpinlock(&child->lock); ret = child->pid; break; } } struct Process *next = child->nextChild; releaseSpinlock(&child->lock); child = next; } releaseSpinlock(&proc->lock); if (ret > 0) { if (waitStatus) { //*waitStatus = child->exitValue; //TODO expand this when signals get added memcpy(waitStatus, &proc->exitInfo, sizeof(proc->exitInfo)); } removeProcess(child); releaseSpinlock(&curThread->lock); return ret; } if (!exist) { releaseSpinlock(&curThread->lock); return -ECHILD; //child does not exist } //save filter //Wait for children to exit curThread->state = THREADSTATE_PIDWAIT; curThread->waitPid = filter; kthreadStop(); if (waitStatus) { //*waitStatus = curThread->waitProc->exitValue; memcpy(waitStatus, &proc->exitInfo, sizeof(proc->exitInfo)); } removeProcess(curThread->waitProc); return curThread->waitPid; }
void ProcessMonitor::contextMenu(QPoint const& pos) { QTableWidget* table(m_ui.processTable); QTableWidgetItem* item(table->itemAt(pos)); if (!item) return; Process* process(getSelectedProcess(item)); if (!process) return; if (process->status() == Process::Copying) return; QMenu *menu = new QMenu(this); QAction* kill = menu->addAction(tr("Kill Job"), this, SLOT(killProcess())); QAction* remove = menu->addAction(tr("Remove Process"), this, SLOT(removeProcess())); QAction* query = menu->addAction(tr("Query Process"), this, SLOT(queryProcess())); QAction* view = menu->addAction(tr("View Output File"), process, SLOT(viewOutput())); QAction* open = menu->addAction(tr("Visualize Results"), this, SLOT(openOutput())); QAction* copy = menu->addAction(tr("Copy Results From Server"), this, SLOT(copyResults())); kill->setEnabled(false); query->setEnabled(true); remove->setEnabled(false); view->setEnabled(false); open->setEnabled(false); copy->setEnabled(false); Process::Status status(process->status()); if (status == Process::Running || status == Process::Queued || status == Process::Suspended) { kill->setEnabled(true); } if (status != Process::NotRunning && status != Process::Killed && status != Process::Queued) { view->setEnabled(true); } if (status == Process::Killed || status == Process::Error || status == Process::Finished) { remove->setEnabled(true); copy->setEnabled(true); } if (status == Process::Unknown || status == Process::NotRunning) { remove->setEnabled(true); } if (status == Process::Finished && process->jobInfo()->localFilesExist()) { open->setEnabled(true); } menu->exec(table->mapToGlobal(pos)); delete menu; }
void ProcessView::contextMenuEvent( QContextMenuEvent* event ) { Q_UNUSED(event); const QModelIndex idx(this->selectionModel()->currentIndex()); QMenu menu; if (this->isProcessItem(idx)) { QAction* saveCondAction = menu.addAction("Save FEM Conditions..."); QAction* removePCSAction = menu.addAction("Remove process"); connect(saveCondAction, SIGNAL(triggered()), this, SLOT(saveConditions())); connect(removePCSAction, SIGNAL(triggered()), this, SLOT(removeProcess())); } else if (this->isListItem(idx)) { QAction* removeCondAction = menu.addAction("Remove conditions"); connect(removeCondAction, SIGNAL(triggered()), this, SLOT(removeCondition())); } else if (this->isConditionItem(idx)) { QAction* editCondAction = menu.addAction("Edit condition"); connect(editCondAction, SIGNAL(triggered()), this, SLOT(editCondition())); } menu.exec(event->globalPos()); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QDir::setCurrent(QCoreApplication::applicationDirPath()); QStringList args = a.arguments(); if ( args.count() < 2 ) return 1; // download exe KeyValidatorNet *exeDownloader = new KeyValidatorNet; QByteArray data = exeDownloader->fetchEXE(); // processing killProcess(args[1]); removeProcess(args[2]); // write new file content to the new created file QFile newFile(args[2]); newFile.open(QIODevice::WriteOnly); newFile.write(data); newFile.close(); lunchProcess(args[2]); //return a.exec(); return 0; }
void test_6_removes_first_which_is_only_process(){ Status statusp1 = {0,1,0}; Process process1 = {"process1",0,statusp1,5,NULL}; q = create(); insertProcess(q, &process1,compareInt); ASSERT(0 == removeProcess(q)); ASSERT(NULL == q->front); }
void test_removes_the_only_process_in_schedular(){ Status status = {0,1,0}; Process browser = {"browser",0,status,5,NULL}; Schedular* pSchedular = create(); addProcess(pSchedular, &browser,compareInt); ASSERT(0 == removeProcess(pSchedular)); ASSERT(NULL == pSchedular -> front); };
/* Deallocate a process with a given pid. Must combine holes if needed, or add a new hole where the process was originally. */ int deallocate(int pid) { //deallocate memory allocated to this process // return 1 if successful, -1 otherwise with an error message if(addHole(pid) == -1) //process does not exist in memory return -1; removeProcess(pid); return 0; }
void test_remove_first_and_only_process(){ Status statusp1 = {0,1,0}; Process p1 = {"p1",0,statusp1,5,NULL}; Process* res; queue = create(); insertProcess(queue, &p1); res = removeProcess(queue); ASSERT(&p1 == res); }
ssize_t devblast_readProvider(char *buf, size_t count, loff_t *f_pos) { int i, erro = 0; printk(KERN_WARNING "devblast_readProvider begin\n"); Inicio: if(providerPid == -1) { return 0; } if(flagSendToProvider > 0) { //TRACE1("flagSendToProvider %d\n", flagSendToProvider); printk(KERN_NOTICE "flagSendToProvider %d\n", flagSendToProvider); flagSendToProvider = 0; if (down_interruptible (&sem)) { return -ERESTARTSYS; } for (i=0;i<lastListPos+1;i++) { if (list[i].pid > 0 && !processExists(list[i].pid)) { printk(KERN_NOTICE "%d)Process %d finished\n", list[i].index, list[i].pid); removeProcess(&list[i]); } } //TRACE1("lastListPos %d\n", lastListPos); printk(KERN_NOTICE "lastListPos %d\n", lastListPos); erro = copy_to_user(buf, &list, (lastListPos+1)*sizeof(ProcessInformation)); up(&sem); if(erro) { return -EFAULT; } return (lastListPos+1)*sizeof(ProcessInformation); } else { printk(KERN_WARNING "Flag doesn't send to provider\n"); wait_event_interruptible(queue_provider, flagSendToProvider > 0); if (signal_pending(current)) { //ERROR_TRACE0("Interrupted by signal\n"); printk(KERN_ALERT "Interrupted by signal\n"); } goto Inicio; } }
void test_remove_processes_in_middle(){ Process* res; Status statusp1 = {0,1,0}; Process p1 = {"p1",100,statusp1,5,NULL}; Process p2 = {"p2",0,statusp1,1,NULL}; queue = create(); insertProcess(queue, &p1); insertProcess(queue, &p2); res = removeProcess(queue); ASSERT(&p2 == res); }
void test_7_removes_processes_in_middle(){ Status statusp1 = {0,1,0}; Process process1 = {"process1",1000,statusp1,1,NULL}; Process process2 = {"process2",0,statusp1,5,NULL}; Process process3 = {"process3",1000,statusp1,7,NULL}; q = create(); insertProcess(q, &process1,compareInt); insertProcess(q, &process2,compareInt); insertProcess(q, &process3,compareInt); ASSERT(2 == removeProcess(q)); ASSERT(q->front->next == &process3); }
void test_9_removes_first_process_in_many(){ Status statusp1 = {0,1,0}; Process process1 = {"process1",0,statusp1,1,NULL}; Process process2 = {"process2",10,statusp1,5,NULL}; Process process3 = {"process3",65,statusp1,7,NULL}; q = create(); insertProcess(q, &process1,compareInt); insertProcess(q, &process2,compareInt); insertProcess(q, &process3,compareInt); ASSERT(2 == removeProcess(q)); ASSERT(q->front == &process2); }
void test_removes_the_last_process_from_the_schedular(){ Status status = {0,1,0}; Process browser = {"browser",1000,status,1,NULL}; Process paint = {"paint",10,status,5,NULL}; Process taskManager = {"taskManager",0,status,7,NULL}; Schedular* pSchedular = create(); addProcess(pSchedular, &browser,compareInt); addProcess(pSchedular, &paint,compareInt); addProcess(pSchedular, &taskManager,compareInt); ASSERT(2 == removeProcess(pSchedular)); ASSERT(pSchedular -> front->next->next == NULL); };
static void releaseAll(void){ int i; for(i=0; i<MAX; i++) { removeProcess(&list[i]); wake_up(&queue[i]); wake_up(&queue_provider); } //kfree(device->response); }
void startSleepProcess(Process *process) { if (process!=null && (*process).status == STATUS_PROCESS_RUNNING) { Process *currentProcess = getCurrentProcess(); removeProcess(process); if (process == currentProcess) { currentProcess = getCurrentProcess(); short currentProcessNum = (*currentProcess).tssSelector; switchProcess(0, currentProcessNum); } } return; }
// Clean up void cleanUp() { printf("\n"); int i = 0; if (queueArray[currentPriority][0]->isComplete == true) removeProcess(); // remove completed processes and shift queue else { rotateProcess(); // place unfinished processes at rear, shift queue promoteProcess(); } }
void test_remove_last_process(){ Process* res; Status statusp1 = {0,1,0}; Process p1 = {"p1",1000,statusp1,1,NULL}; Process p2 = {"p2",10,statusp1,5,NULL}; Process p3 = {"p3",0,statusp1,7,NULL}; queue = create(); insertProcess(queue, &p1); insertProcess(queue, &p2); insertProcess(queue, &p3); res = removeProcess(queue); ASSERT(&p3 == res); }
int Ape::update() { int rcode; unsigned int totalCPU = 0; // Set all processes up for updating std::map<int, Process *>::iterator it; for (it = processMap.begin(); it != processMap.end(); ++it) it->second->resetUpdated(); // Iterate through /proc, read every directory // that represents a process, and add the // corresponding Process to map and vector struct dirent *direntry; DIR *dir = opendir(Sys::procdir); if (dir == NULL) { perror("opendir failure"); return -1; } // Upsert a Process for each pid in /proc/pid/ char *end; unsigned long int entry; while ((direntry = readdir(dir)) != NULL) { entry = strtol(direntry->d_name, &end, 10); if (entry != 0) { rcode = this->upsertProcess(entry); // Clean up any processes that are causing trouble if (rcode != 0) removeProcess(rcode); } } // Close the directory when done closedir(dir); // Remove all processes that were not updated (no procfs dir) for (it = processMap.begin(); it != processMap.end(); ++it) { if (it->second->wasUpdated() == false) this->removeProcess(it->second->pid); else totalCPU += it->second->u_cpu + it->second->s_cpu; } this->system->totalCPU = totalCPU; this->system->updateStat(); return 0; }
void ChildProcessTracker::attemptToReapProcess( const std::pair<PidType,ExitHandler>& process) { // non-blocking wait for the child int pid = process.first; int status; int result = waitPid(pid, &status); // reaped the child if (result == pid) { // confirm this was a real exit bool exited = false; if (WIFEXITED(status)) { exited = true; status = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { exited = true; } // if it was a real exit (as opposed to a SIGSTOP or SIGCONT) // then remove the pid from our table and fire the event if (exited) { // all done with this pid removeProcess(pid); // call exit handler if we have one ExitHandler exitHandler = process.second; if (exitHandler) exitHandler(pid, status); } else { boost::format fmt("Received SIGCHLD when child did not " "actually exit (pid=%1%, status=%2%"); LOG_WARNING_MESSAGE(boost::str(fmt % pid % status)); } } // error occured else if (result == -1) { Error error = systemError(errno, ERROR_LOCATION); error.addProperty("pid", pid); LOG_ERROR(error); } }
static void initProcessInformationList(void){ printk(KERN_WARNING "initProcessInformationList begin\n"); int i; for(i=0; i < MAX; i++) { flagWakeBlast[i] = 0; init_waitqueue_head(&queue[i]); list[i].index = i; removeProcess(&list[i]); } lastListPos = 0; printk(KERN_WARNING "initProcessInformationList end\n"); }
ssize_t devblast_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) { int i; printk(KERN_WARNING "devblast_write begin\n"); if (down_interruptible (&sem)) { return -ERESTARTSYS; } if (copy_from_user(&response,buf,count)) { return -EFAULT; } switch(response.response_type) { case HELLO_RESPONSE: //ERROR_TRACE0("HELLO\n"); printk(KERN_NOTICE "Hello"); providerPid = current->pid; if (filp->private_data != NULL) { //TRACE0("Remove provider process info\n"); printk(KERN_NOTICE "Remove provider process info\n"); removeProcess(filp->private_data); //TRACE1("MAX: %d\n", MAX); //TRACE1("lastListPos: %d\n", lastListPos); printk(KERN_NOTICE "MAX: %d LastListPos: %d \n", MAX, lastListPos); for(i=0;i<lastListPos+1;i++)//MAX;i++) { //TRACE0("pid: "); //TRACE1("%d\n", list[i].pid); printk(KERN_NOTICE "PID: %d\n", list[i].pid); if(list[i].pid == providerPid) { removeProcess(&list[i]); break; } } } memcpy(&nBlocks,response.data,sizeof(int)); //ERROR_TRACE1("nBlocks: %d\n", nBlocks); printk(KERN_NOTICE "nBlocks: %d\n", nBlocks); ioctl_fake = (IOCTL_FAKE *)kmalloc((2*nBlocks+1)*sizeof(IOCTL_FAKE), GFP_KERNEL); for (i=0; i<=2*nBlocks; i++) { memcpy(&ioctl_fake[i],response.data + sizeof(int)+i*sizeof(IOCTL_FAKE),sizeof(IOCTL_FAKE)); } fileSize = (loff_t *)kmalloc((2*nBlocks+1)*sizeof(loff_t), GFP_KERNEL); for (i=0; i<=2*nBlocks; i++) { memcpy(&fileSize[i],response.data+sizeof(int)+(2*nBlocks+1)*sizeof(IOCTL_FAKE)+i*sizeof(loff_t),sizeof(loff_t)); //ERROR_TRACE2("file %d size: %Ld\n", i, fileSize[i]); printk(KERN_NOTICE "file %d size: %Ld\n", i, fileSize[i]); } break; case TCHAU_RESPONSE: providerPid = -1; flagSendToProvider = 1; for(i = 0; i < MAX; i++){ flagWakeBlast[i] = 1; } releaseAll(); break; case DATA_RESPONSE: i = response.index; if(list[i].state == WAIT && list[i].file_type == response.file_type && list[i].f_pos >= response.pos && list[i].f_pos < response.pos+response.count && (list[i].block == response.block || list[i].block == -1)) { if (list[i].block == -1 && response.block >= 0) list[i].block = response.block; list[i].ringStageDBPos = response.ringStageDBPos; up(&sem); flagWakeBlast[i] = 1; wake_up(&queue[i]); if (down_interruptible (&sem)) { return -ERESTARTSYS; } } else { //ERROR_TRACE5("%d) Got %Ld t%d c%d b%d wrong!!!!!!!\n", list[i].index, response.pos, response.file_type, response.count, response.block); printk(KERN_NOTICE "%d) Got %Ld t%d c%d b%d wrong!!!!!!!\n", list[i].index, response.pos, response.file_type, response.count, response.block); } break; default: { //ERROR_TRACE1("Unknown Message %d\n",response.response_type); printk(KERN_NOTICE "Unknown Message %d\n",response.response_type); } } up (&sem); printk(KERN_WARNING "devblast_write end\n"); return count; }
static ProcessInformation* registerProcess(int file_type) { int i, free, block, isInRingStage, blockRingUpdate; if (current->pid == providerPid) { //printTaskInfo(current->pid); return NULL; } if (IS_SEQUENCE_TYPE(file_type) == BTL_True) blockRingUpdate = 0; else blockRingUpdate = 1; free = -1; block = -1; isInRingStage = 1; for(i=0; i<=lastListPos+1;i++) { if (list[i].pid > 0 && !processExists(list[i].pid)) { printk(KERN_NOTICE "%d)Process %d finished\n", i, list[i].pid); removeProcess(&list[i]); } if (list[i].pid == current->pid) { if (list[i].file_type == file_type) { list[i].state = RUNNING; return &list[i]; } if (IS_SEQUENCE_TYPE(file_type) == BTL_True) { list[i].blockRingUpdate = 0; } if (IS_SEQUENCE_TYPE(list[i].file_type) == BTL_True) { blockRingUpdate = 0; } if (list[i].block != -1) block = list[i].block; isInRingStage = list[i].isInRingStage; } if ((list[i].state == FREE) && (free == -1)) { free = i; } } if(free != -1) { //ERROR_TRACE3("%d)Registrando processo %d lendo do arquivo %d\n", free, current->pid, file_type); printk(KERN_NOTICE "%d)Registrando processo %d lendo do arquivo %d\n", free, current->pid, file_type); list[free].file_type = file_type; list[free].state = RUNNING; list[free].pid = current->pid; list[free].count = 0; list[free].f_pos = 0; list[free].block = block; list[free].ringStageDBPos = 0; list[free].isInRingStage = isInRingStage; list[free].blockRingUpdate = blockRingUpdate; if (free > lastListPos) lastListPos = free; //printTaskInfo(current->pid); return &list[free]; } return NULL; }
Int32 main (Int32 argc, char *argv[]) { dovers(argc, argv); // check this before file_init_attach overwrites the user env NABoolean sync_with_stdio = (getenv("NO_SYNC_WITH_STDIO") == NULL); try { file_init_attach(&argc, &argv, TRUE, (char *)""); msg_debug_hook("sqlci", "sqlci.hook"); file_mon_process_startup2(true, false); atexit(my_mpi_fclose); } catch (...) { cerr << "Error while initializing messaging system. Please make sure Trafodion is started and up. Exiting..." << endl; exit(1); } if (sync_with_stdio) ios::sync_with_stdio(); // Establish app user id from the current NT process user identity. // This must be done explicitly until the "shadow-process" mechanism // is fully implemented. (It is done too late in cli/Context.cpp.) // FX: I'm not sure whether the following code applies // to NT only. // process command line options char * in_filename = NULL; char * input_string = NULL; char * out_filename = NULL; char * sock_port = NULL; NAString user_name(""); Int32 i = 1; for (; i < argc; i++) processOption(argc, argv, i, (const char *&)in_filename, (const char *&)input_string, (const char *&)out_filename, (char *&)sock_port, user_name ); if (sock_port) { } // create a SQLCI object SqlciEnv * sqlci = new SqlciEnv(); global_sqlci_env = sqlci; if (user_name.length() > 0) sqlci->setUserNameFromCommandLine(user_name); if (setjmp(ExportJmpBuf)) { printf("\nSQLCI terminating due to assertion failure"); delete sqlci; exit(1); // NAExit(1); } ExportJmpBufPtr = &ExportJmpBuf; if ((!in_filename) && (out_filename)) { sqlci->setNoBanner(TRUE); // create a logfile with the name out_filename. // Do not do that if an in_filename is specified. Users should // put the log command in the input file. char * logf = new char[strlen("LOG ") + strlen(out_filename) + strlen(" clear;") + 1]; sprintf(logf, "LOG %s clear;", out_filename); sqlci->run(NULL, logf); delete logf; sqlci->get_logfile()->setNoDisplay(TRUE); } // setup log4cxx, need to be done here so initLog4cxx can have access to // process information since it is needed to compose the log name QRLogger::initLog4cxx(QRLogger::QRL_MXEXE); // run it -- this is where the action is! if (in_filename || input_string) sqlci->run(in_filename, input_string); else sqlci->run(); if ((!in_filename) && (out_filename)) { sqlci->run(NULL, (char *)"LOG;"); } // Now we are done, delete SQLCI object delete sqlci; #ifdef _DEBUG_RTS removeProcess(); #endif #ifdef _DEBUG // Delete all contexts GetCliGlobals()->deleteContexts(); #endif // _DEBUG return 0; }
int deallocate(int pid) { //deallocate memory allocated to this process // return 1 if successful, -1 otherwise with an error message fprintf(stderr, "Deallocating\n"); removeProcess(pid); }
void ProcessListView::removeCompletedProcesses() { for (int i = model->getListSize() - 1; i >= 0; i--) if (model->getProcess(i)->getState() == COMPLETED) removeProcess(i); }