Exemplo n.º 1
0
void proctable_exit_process(struct proc *proc_exited, int exitcode) {
  // DEBUG(DB_EXEC, "Exiting PID: %d from proctable\n", getPID(proc_exited));

  KASSERT(proc_exited != NULL);
  KASSERT(proc_exited->p_pid > 0);

  // set the process state to exited
  setState(proc_exited, PROC_EXITED);

  // encode the exit code as per the docs.
  setExitcode(proc_exited, _MKWAIT_EXIT(exitcode));

  // Next we need to evaluate some cases:
  // If proc_exited has living children, they should now have a NULL parent.
  // If proc_exited has dead children, they should now be destroyed.

  int exitedPID = getPID(proc_exited);

  // Find the children of proc_exited.
  for (int i = MIN_PID; i < pidLimit; i++) {
    struct proc* cur = procarray_get(procTable, i);
    if (cur != NULL && getPPID(cur) == exitedPID) {
      // Check state of child
      int state = getState(cur);
      
      // A running child has its parent set to NULL
      if (state == PROC_RUNNING) {
        setPPID(cur, PROC_NO_PID);
      }

      // An exited child can now be completely removed.
      else if (state == PROC_EXITED) {
        proctable_remove_process(cur);
      }
    }
  }

  // If proc_exited has no parent, it can be removed
  if (getPPID(proc_exited) == PROC_NO_PID) {
    proctable_remove_process(proc_exited);
  }

  // Otherwise if proc_exited has a parent
  // then proc_exited must wake its potentially waiting parent
  else {
    cv_signal(proc_exited->wait_cv, procTableLock);
  }
}
Exemplo n.º 2
0
int ifb_getProcStatus(int type)
{
	char			*dname, *ver, fname[100], pname[PROC_NAME_LEN];
	int				fd, status, pid, procIndex;
	DIR				*dirp;
	time_t			sysuptime;
	struct dirent	*direntp;
	struct stat		st;

#if 0
	if(get_system_uptime(&sysuptime))
		return -1;
#endif

	if( (dirp = opendir(PROC_DIR)) == NULL)
	{
		fprintf(stderr, "\n opendir fail[%s]; err=%d(%s)\n\n", PROC_DIR, errno, strerror(errno));
		return -1;
	}

	while( (direntp = readdir(dirp)) != NULL)
	{
		dname = direntp->d_name;
		if(!isdigit(*dname))
			continue;
		pid = atoi(dname);

		sprintf(fname, "/proc/%d/cmdline", pid);

		/* get the process owner */
		if( (status = stat(fname, &st)) != 0)
			continue;

		if( (fd = open(fname, O_RDONLY)) < 0)
			continue;
		else
		{
			memset(pname, 0x00, PROC_NAME_LEN);
			if(read(fd, pname, PROC_NAME_LEN-1) < 0)
			{
				close(fd);
				continue;
			}
			else
			{
				close(fd);
				if( (procIndex = ifb_getProcIndex (pname)) < 0)
					continue;

				if(confProcTbl[procIndex].runCnt > 0)
				{
					if(getPPID(pid) != 1)
						continue;
				}
				confProcTbl[procIndex].runCnt++;
				confProcTbl[procIndex].pid = pid;

				strcpy(confProcTbl[procIndex].startTime, "-");
			#if 0
				get_proc_starttime(pid, sysuptime, NULL, confProcTbl[procIndex].startTime);
				strftime (confProcTbl[procIndex].startTime, 32, "%m-%d %H:%M",localtime((time_t*)&(st.st_atime)));
			#endif

				if( (ver = get_ver_str(pname)) != NULL)
				{
					fprintf(stderr, "It fails to get version information -[%s].\n", pname);
					strncpy(confProcTbl[procIndex].procVersion, "UNKNOWN", 10);
				}
				else
				{
					if(strlen(ver) == 0)
						strncpy(confProcTbl[procIndex].procVersion, "UNKNOWN", 10);
					else
						strncpy(confProcTbl[procIndex].procVersion, ver, 10);
				}
			}
		}
	}
	closedir(dirp);

	return 1;
} //----- End of ifb_getProcStatus -----//
Exemplo n.º 3
0
void printline(HANDLE hProcess, DWORD dProcessId, PTCHAR szFileName, const MEMORY_BASIC_INFORMATION* pInfo)
{
    static unsigned long id = 1;
    int dParentProcessId = getPPID(dProcessId);
    BOOL read = FALSE;
    BOOL write = FALSE;
    BOOL exec = FALSE;
    BOOL cop = FALSE;

    if ((pInfo->AllocationProtect & PAGE_READONLY))
    {
        read = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_READWRITE))
    {
        read = TRUE;
        write = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_WRITECOPY))
    {
        read = TRUE;
        write = TRUE;
        cop = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_EXECUTE))
    {
        exec = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_EXECUTE_READ))
    {
        read = TRUE;
        exec = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_EXECUTE_READWRITE))
    {
        read = TRUE;
        write = TRUE;
        exec = TRUE;
    }
    else if ((pInfo->AllocationProtect & PAGE_EXECUTE_WRITECOPY))
    {
        read = TRUE;
        write = TRUE;
        exec = TRUE;
        cop = TRUE;
    }
    else if (!(pInfo->AllocationProtect & PAGE_NOACCESS) && pInfo->AllocationProtect)
    {
        _tprintf("ERROR: unknown protection for page: %lu\n", pInfo->AllocationProtect);
        // error: unknown setting for page
    }
    /*
     * info.BaseAddress; // PVOID
     * info.AllocationBase; // PVOID
     * info.AllocationProtect; //DWORD: Flags lors de l'allocation
     * info.RegionSize; // SIZE_T
     * info.State; // DWORD: Flags
     * info.Protect; //DWORD: Flags courant
     * info.Type; DWORD
     */
    _tprintf(FORMAT, ++id, dProcessId, dParentProcessId, szFileName,
             pInfo->BaseAddress, pInfo->RegionSize,
             read, write, exec, cop);
}