void process_initialize(PROCESS* newProcess, char* name, int(*processFunc)(int, char**), int argc, char** argv, int stacklength, void(*cleaner)(void), int tty, int groundness, int status, int priority, int parentPID) { for (int i = 0; i < argc; i++) { int len = strlen(argv[i]) + 1; newProcess->argv[i] = (char*) kmalloc(len); memcpy(newProcess->argv[i], argv[i], len); } newProcess->argc = argc; memcpy(newProcess->name, name, strlen(name) + 1); newProcess->ownerUid = session_getEuid(); newProcess->pid = getNextPID(); newProcess->stacksize = stacklength; newProcess->stack = paging_reserveStack(stacklength); log(L_DEBUG, "%s starts at 0x%x to 0x%x", name, newProcess->stack, newProcess->stack + stacklength - 1); newProcess->ESP = loadStackFrame(processFunc, newProcess->stack + stacklength - 1, argc, newProcess->argv, cleaner); newProcess->tty = tty; newProcess->lastCalled = 0; newProcess->priority = priority; newProcess->groundness = groundness; newProcess->parent = parentPID; newProcess->status = status; newProcess->waitingFlags = -1; for (int i = 0; i < MAX_FILES_PER_PROCESS; i++) { newProcess->fd_table[i].mask = 0; } log(L_DEBUG, "Creating new process: %s - PID: %d. Parent: %d\n", newProcess->name, newProcess->pid, newProcess->parent); }
bool CatanRoom::AddUser( CatanUser *user ) { if( GetNumPlayers() >= config->GetMaxPlayers() ) return false; if( user->InGame() || user->InLobby() ) return false; int id = getNextPID( players ); CatanPlayer* player = new CatanPlayer(id, user, this); //set the host if( !host ) setHost( player ); players[id] = player; playerCount++; LOG_DEBUG( "Lobby player count: " << GetNumPlayers() << endl ); player->SetState(PLAYER_STATE::IN_LOBBY); //tell the current players in the room that this user has joined for( int i = 0; i < GetMaxPlayers(); i++ ) { CatanPlayer *occupant = players[i]; if( !occupant ) continue; net::Begin(NETWORK_COMMAND::SERVER_ROOM_USER_JOINED); net::AddShort(this->GetID()); net::AddByte(player->GetID()); net::AddString(player->GetName()); net::Send(occupant->GetUser()); } //tell this user about the current players in the room net::Begin(NETWORK_COMMAND::SERVER_ROOM_PLAYERS); net::AddByte(GetNumPlayers()-1); //don't include the new player //send the host first. net::AddByte(host->GetID()); net::AddString(host->GetName()); net::AddBool(readyPlayers[host->GetID()]); for( int i = 0; i < GetMaxPlayers(); i++ ) { CatanPlayer *occupant = players[i]; if( !occupant ) continue; if( occupant != host && occupant != player ) { net::AddByte(occupant->GetID()); net::AddString(occupant->GetName()); net::AddBool(readyPlayers[occupant->GetID()]); } } net::Send(user); //send the game configuration transmitConfigFull(user); //if the user gets destroyed, remove him from the room connect( player, SIGNAL(destroying()), this, SLOT(onPlayerDestroying())); connect( player, SIGNAL(requestLeaveRoom()), this, SLOT(onPlayerLeave())); connect( player, SIGNAL(readyUp(bool)), this, SLOT(readyUp(bool))); emit addedPlayer(player); return true; }
void Monitor::procProcesses() { PIDList deletes; PIDList adds; unsigned long long totalTicks = 0; if ( fCPUTotalTicks.size() > 0 ) { totalTicks = fCPUTotalTicks[0]; } ProcessStatHandler statHandler(fProcMap, totalTicks); ProcessStatMHandler statMHandler(fProcMap, fTotalMemory); ProcessCmdLineHandler cmdLineHandler(fProcMap, fAppNameMap); QStringList procList = fProcReader.getProcList(); QStringListIterator slIterator(procList); pid_t pid; int iteration = 0; while ( (pid = getNextPID(slIterator, iteration)) != 0 ) { iteration++; const QString pidStr = QString::number(pid); QString pathStatM("/proc/" + pidStr + "/statm"); QString pathCmdLine("/proc/" + pidStr + "/cmdline"); QString pathStat("/proc/" + pidStr + "/stat"); if ( !fProcMap.contains(pid) ) { fProcMap[pid]; adds.append(pid); } const QString oldName = fProcMap.value(pid).getStatName(); if ( fProcReader.readProcFile(pathStat, statHandler, 1, pid) != 0 ) { qCritical() << "Error reading process stat file " << pid << "\n"; continue; } if ( !oldName.isEmpty() && oldName != fProcMap.value(pid).getStatName() ) { fProcMap.remove(pid); fProcMap[pid]; deletes.append(pid); adds.append(pid); if ( fProcReader.readProcFile(pathStat, statHandler, 1, pid) != 0 ) { qCritical() << "Error reading process stat file " << pid << "\n"; continue; } } if ( fProcReader.readProcFile(pathStatM, statMHandler, 1, pid) != 0 ) { qCritical() << "Error reading process mstat file " << pid << "\n"; continue; } if ( fProcMap.value(pid).getNameState() == 0 ) { if ( fProcReader.readProcFile(pathCmdLine, cmdLineHandler, 1, pid) != 0 ) { qCritical() << "Error reading process cmdline file " << pid << "\n"; continue; } } } QMapIterator<pid_t, ProcInfo> iterator(fProcMap); while ( iterator.hasNext() ) { iterator.next(); const pid_t pid = iterator.key(); const QString pidStr = QString::number(pid); QString pathStat("/proc/" + pidStr + "/stat"); if ( !QFile::exists(pathStat) ) { fProcMap.remove(pid); deletes.append(pid); } } emit processChanged(&fProcMap, adds, deletes); }