Example #1
0
int do_procctl(message *msg)
{
	endpoint_t proc;
	struct vmproc *vmp;

	if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
		printf("VM: bogus endpoint VM_PROCCTL %d\n",
			msg->VMPCTL_WHO);
		return EINVAL;
	}
	vmp = &vmproc[proc];

	switch(msg->VMPCTL_PARAM) {
		case VMPPARAM_CLEAR:
			if(msg->m_source != RS_PROC_NR
				&& msg->m_source != VFS_PROC_NR)
				return EPERM;
			free_proc(vmp);
			if(pt_new(&vmp->vm_pt) != OK)
				panic("VMPPARAM_CLEAR: pt_new failed");
			pt_bind(&vmp->vm_pt, vmp);
			return OK;
		default:
			return EINVAL;
	}


	return OK;
}
Example #2
0
/*===========================================================================*
 *				do_exit					     *
 *===========================================================================*/
int do_exit(message *msg)
{
	int proc;
	struct vmproc *vmp;

SANITYCHECK(SCL_FUNCTIONS);

	if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
		printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
		return EINVAL;
	}
	vmp = &vmproc[proc];

	if(!(vmp->vm_flags & VMF_EXITING)) {
		printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
		return EINVAL;
	}

	{
		/* Free pagetable and pages allocated by pt code. */
SANITYCHECK(SCL_DETAIL);
		free_proc(vmp);
SANITYCHECK(SCL_DETAIL);
	} 
SANITYCHECK(SCL_DETAIL);

	/* Reset process slot fields. */
	clear_proc(vmp);

SANITYCHECK(SCL_FUNCTIONS);
	return OK;
}
Example #3
0
/*===========================================================================*
 *				pm_reboot				     *
 *===========================================================================*/
void pm_reboot()
{
  /* Perform the VFS side of the reboot call. */
  int i;
  struct fproc *rfp;

  do_sync();

  /* Do exit processing for all leftover processes and servers,
   * but don't actually exit them (if they were really gone, PM
   * will tell us about it).
   */
  for (i = 0; i < NR_PROCS; i++) {
	rfp = &fproc[i];
	if (rfp->fp_endpoint == NONE) continue;

	/* Don't just free the proc right away, but let it finish what it was
	 * doing first */
	lock_proc(rfp, 0);
	free_proc(rfp, 0);
	unlock_proc(rfp);
  }

  do_sync();
  unmount_all();
}
Example #4
0
File: misc.c Project: Hooman3/minix
/*===========================================================================*
 *				pm_exit					     *
 *===========================================================================*/
void pm_exit(void)
{
/* Perform the file system portion of the exit(status) system call.
 * This function is called from the context of the exiting process.
 */

  free_proc(FP_EXITING);
}
Example #5
0
static void free_old_procs(void) {
    int i;

    for (i = 0; i < num_old_procs; i++)
        if (old_procs[i])
            free_proc(old_procs[i]);

    free(old_procs);
}
Example #6
0
File: misc.c Project: jkiiski/minix
/*===========================================================================*
 *				pm_reboot				     *
 *===========================================================================*/
void pm_reboot()
{
/* Perform the VFS side of the reboot call. */
  int i;
  struct fproc *rfp;

  do_sync();

  /* Do exit processing for all leftover processes and servers, but don't
   * actually exit them (if they were really gone, PM will tell us about it).
   * Skip processes that handle parts of the file system; we first need to give
   * them the chance to unmount (which should be possible as all normal
   * processes have no open files anymore).
   */
  for (i = 0; i < NR_PROCS; i++) {
	rfp = &fproc[i];

	/* Don't just free the proc right away, but let it finish what it was
	 * doing first */
	lock_proc(rfp, 0);
	if (rfp->fp_endpoint != NONE && find_vmnt(rfp->fp_endpoint) == NULL)
		free_proc(rfp, 0);
	unlock_proc(rfp);
  }

  do_sync();
  unmount_all(0 /* Don't force */);

  /* Try to exit all processes again including File Servers */
  for (i = 0; i < NR_PROCS; i++) {
	rfp = &fproc[i];

	/* Don't just free the proc right away, but let it finish what it was
	 * doing first */
	lock_proc(rfp, 0);
	if (rfp->fp_endpoint != NONE)
		free_proc(rfp, 0);
	unlock_proc(rfp);
  }

  do_sync();
  unmount_all(1 /* Force */);

}
Example #7
0
        static void deinit_library(HMODULE)
        {
#if defined(__AIX__) && defined(__GNUC__)
            dlerror();              // Clear the error state.
            typedef void (*free_proc_type)();
            free_proc_type free_proc =
                (free_proc_type)MyGetProcAddress(dll_hand, "_GLOBAL__DD");
            if (free_proc)
                free_proc();
#endif
        }
Example #8
0
void free_proc(proc_list *x) {
    if(!x) return;
    int i;
    if(x->redir_type != -1) {
        for(i=0; x->argv[i] != NULL; i++)
            free(x->argv[i]);
        free(x->argv);
        if(x->redir_type != 0)
            free(x->redir);
        if(x->next) free_proc(x->next);
    }
    free(x);
}
Example #9
0
// runs processes in queue
bool run_processes(node_t** head, int priority)
{

    bool check_priority = priority >= 0;
    node_t* curr_node = *head;
    proc* currproc;
    while(curr_node)
    {
        if(!check_priority || curr_node->process.priority == priority)
        {
            // get it
            currproc = &curr_node->process;



            // run it
            if(launch_process_as_child(currproc))
            {
                // child shouldn't spawn more children
                fprintf(stderr, "Error: pid %d reached this pointfor some reason\n", getpid());
                return false;
            }


            printf("[%d]process name '%s' priority %d pid %d runtime %d\n", getpid(), currproc->name, currproc->priority, currproc->pid, currproc->runtime);
            


            // be rid of it
            free_proc(currproc);
            if(curr_node == *head)
            {
                curr_node = curr_node->next;
                pop(head);
            } else {
                delete_pid(*head, currproc->pid);
                if(curr_node)
                    curr_node = curr_node->next;
            }
        } else {
            curr_node = curr_node->next;
        }

    }



    
    // you never got to be the one in the tank
    return true;
}
Example #10
0
/* Tell children that I am dead...
 */
void tell_children(pcb_t *proc) {
    dnode_t *node = proc->children->head;
    while(node) {
        pcb_t *child = node->data;
        log_info("exiting PID(%d) telling children PID(%d)", proc->pid, child->pid);
        child->parent = NULL;
        if(child->state == ZOMBIE) {
             int rc = free_proc(child);
             if(rc) {
                log_err("Cannot free child PID(%d)", child);
             }
        }
        node = node->next;
    }
}
Example #11
0
int Y_Wait(int * status_ptr, UserContext *user_context){
    // Check if it is worth to wait
    if(!any_child_active(running_proc) && !running_proc->zombie->size) {
        log_info("Not woth to wait!! #zombie %d, and no children is active", running_proc->zombie->size);
        running_proc->exit_code = 1;
        return 1;       // No body treat pid 1 and child process, so I make it as exit_code
    }

    // Wait operations
    log_info("PID(%d) about to sleep until one of my child wake me up", running_proc->pid);
    en_wait_queue(running_proc);
    next_schedule(user_context);

    // Back to life!
    if(running_proc->wait_zombie) {
        log_info("PID(%d) wake up and going to run again!", running_proc->pid);
        pcb_t* zombie = de_zombie_queue(running_proc);
        log_info("PID(%d) get zombie %p!", running_proc->pid, zombie);
        *status_ptr = zombie->exit_code;
        //log_info("PID(%d) get zombie status!", running_proc->pid);
        running_proc->exit_code = zombie->pid; 
        //log_info("Get my zombie pid(%d) exit code %d", zombie->pid, zombie->exit_code);
        free_proc(zombie);
        running_proc->wait_zombie = 0;
        return running_proc->exit_code;
    } else {
        log_info("I am not waiting");
        return 0; 
    }


	//IF there are zombie children
		//REMOVE their PCB from PCB list
		//FREE PCB
	//END IF

	//IF there are no live children
		//REPORT ERROR
	//END IF

	//BLOCK current process
}
Example #12
0
File: misc.c Project: Hooman3/minix
/*===========================================================================*
 *				pm_reboot				     *
 *===========================================================================*/
void pm_reboot()
{
/* Perform the VFS side of the reboot call. This call is performed from the PM
 * process context.
 */
  message m_out;
  int i, r;
  struct fproc *rfp, *pmfp;

  pmfp = fp;

  do_sync();

  /* Do exit processing for all leftover processes and servers, but don't
   * actually exit them (if they were really gone, PM will tell us about it).
   * Skip processes that handle parts of the file system; we first need to give
   * them the chance to unmount (which should be possible as all normal
   * processes have no open files anymore).
   */
  /* This is the only place where we allow special modification of "fp". The
   * reboot procedure should really be implemented as a PM message broadcasted
   * to all processes, so that each process will be shut down cleanly by a
   * thread operating on its behalf. Doing everything here is simpler, but it
   * requires an exception to the strict model of having "fp" be the process
   * that owns the current worker thread.
   */
  for (i = 0; i < NR_PROCS; i++) {
	rfp = &fproc[i];

	/* Don't just free the proc right away, but let it finish what it was
	 * doing first */
	if (rfp != fp) lock_proc(rfp);
	if (rfp->fp_endpoint != NONE && find_vmnt(rfp->fp_endpoint) == NULL) {
		worker_set_proc(rfp);	/* temporarily fake process context */
		free_proc(0);
		worker_set_proc(pmfp);	/* restore original process context */
	}
	if (rfp != fp) unlock_proc(rfp);
  }

  do_sync();
  unmount_all(0 /* Don't force */);

  /* Try to exit all processes again including File Servers */
  for (i = 0; i < NR_PROCS; i++) {
	rfp = &fproc[i];

	/* Don't just free the proc right away, but let it finish what it was
	 * doing first */
	if (rfp != fp) lock_proc(rfp);
	if (rfp->fp_endpoint != NONE) {
		worker_set_proc(rfp);	/* temporarily fake process context */
		free_proc(0);
		worker_set_proc(pmfp);	/* restore original process context */
	}
	if (rfp != fp) unlock_proc(rfp);
  }

  do_sync();
  unmount_all(1 /* Force */);

  /* Reply to PM for synchronization */
  memset(&m_out, 0, sizeof(m_out));

  m_out.m_type = VFS_PM_REBOOT_REPLY;

  if ((r = ipc_send(PM_PROC_NR, &m_out)) != OK)
	panic("pm_reboot: ipc_send failed: %d", r);
}
Example #13
0
void execute(char *cmd) {
    proc_list *proclist = parse_proc(cmd);
    exec_proc(proclist);
    free_proc(proclist);
}
Example #14
0
caddr_t
get_process_info(struct system_info * si,
				 struct process_select * sel,
				 int compare_index, char *conninfo, int mode)
{
	struct timeval thistime;
	double		timediff,
				alpha,
				beta;
	struct top_proc *proc;
	pid_t		pid;
	unsigned long now;
	unsigned long elapsed;
	int			i;

	/* calculate the time difference since our last check */
	gettimeofday(&thistime, 0);
	if (lasttime.tv_sec)
	{
		timediff = ((thistime.tv_sec - lasttime.tv_sec) +
					(thistime.tv_usec - lasttime.tv_usec) * 1e-6);
	}
	else
	{
		timediff = 0;
	}
	lasttime = thistime;

	/* round current time to a second */
	now = (unsigned long) thistime.tv_sec;
	if (thistime.tv_usec >= 500000)
	{
		now++;
	}

	/* calculate constants for the exponental average */
	if (timediff > 0.0 && timediff < 30.0)
	{
		alpha = 0.5 * (timediff / 30.0);
		beta = 1.0 - alpha;
	}
	else
	{
		alpha = beta = 0.5;
	}
	timediff *= HZ;				/* convert to ticks */

	/* mark all hash table entries as not seen */
	for (i = 0; i < HASH_SIZE; ++i)
	{
		for (proc = ptable[i]; proc; proc = proc->next)
		{
			proc->state = 0;
		}
	}

	/* read the process information */
	{
		int			total_procs = 0;
		struct top_proc **active;

		int			show_idle = sel->idle;
		int			show_uid = sel->uid != -1;

		int			i;
		int			rows;
		PGconn	   *pgconn;
		PGresult   *pgresult = NULL;

		memset(process_states, 0, sizeof(process_states));

		pgconn = connect_to_db(conninfo);
		if (pgconn != NULL)
		{
			pgresult = pg_processes(pgconn);
			rows = PQntuples(pgresult);
		}
		else
		{
			rows = 0;
		}
		for (i = 0; i < rows; i++)
		{
			char	   *procpid = PQgetvalue(pgresult, i, 0);
			struct top_proc *pp;
			unsigned long otime;

			pid = atoi(procpid);

			/* look up hash table entry */
			proc = pp = ptable[HASH(pid)];
			while (proc && proc->pid != pid)
			{
				proc = proc->next;
			}

			/* if we came up empty, create a new entry */
			if (proc == NULL)
			{
				proc = new_proc();
				proc->pid = pid;
				proc->next = pp;
				ptable[HASH(pid)] = proc;
				proc->time = 0;
				proc->wcpu = 0;
			}

			otime = proc->time;

			read_one_proc_stat(pid, proc, sel);
			if (sel->fullcmd == 2)
				update_procname(proc, PQgetvalue(pgresult, i, 1));

			if (proc->state == 0)
				continue;

			total_procs++;
			process_states[proc->state]++;

			if (timediff > 0.0)
			{
				if ((proc->pcpu = (proc->time - otime) / timediff) < 0.0001)
				{
					proc->pcpu = 0;
				}
				proc->wcpu = proc->pcpu * alpha + proc->wcpu * beta;
			}
			else if ((elapsed = (now - boottime) * HZ - proc->start_time) > 0)
			{
				/*
				 * What's with the noop statement? if ((proc->pcpu =
				 * (double)proc->time / (double)elapsed) < 0.0001) {
				 * proc->pcpu; }
				 */
				proc->wcpu = proc->pcpu;
			}
			else
			{
				proc->wcpu = proc->pcpu = 0.0;
			}
		}
		if (pgresult != NULL)
			PQclear(pgresult);
		PQfinish(pgconn);

		/* make sure we have enough slots for the active procs */
		if (activesize < total_procs)
		{
			pactive = (struct top_proc **) realloc(pactive,
									sizeof(struct top_proc *) * total_procs);
			activesize = total_procs;
		}

		/* set up the active procs and flush dead entries */
		active = pactive;
		for (i = 0; i < HASH_SIZE; i++)
		{
			struct top_proc *last;
			struct top_proc *ptmp;

			last = NULL;
			proc = ptable[i];
			while (proc != NULL)
			{
				if (proc->state == 0)
				{
					ptmp = proc;
					if (last)
					{
						proc = last->next = proc->next;
					}
					else
					{
						proc = ptable[i] = proc->next;
					}
					free_proc(ptmp);
				}
				else
				{
					if ((show_idle || proc->state == 1 || proc->pcpu) &&
						(!show_uid || proc->uid == sel->uid))
					{
						*active++ = proc;
						last = proc;
					}
					proc = proc->next;
				}
			}
		}

		si->p_active = active - pactive;
		si->p_total = total_procs;
		si->procstates = process_states;
	}

	/* if requested, sort the "active" procs */
	if (si->p_active) {
		if (mode == MODE_IO_STATS) {
			qsort(pactive, si->p_active, sizeof(struct top_proc *),
			  		io_compares[compare_index]);
		}
		else
		{
			qsort(pactive, si->p_active, sizeof(struct top_proc *),
			  		proc_compares[compare_index]);
		}
	}

	/* don't even pretend that the return value thing here isn't bogus */
	nextactive = pactive;
	return (caddr_t) 0;
}