void priority (struct process *proc) {
    int time, start, end, highest;
    struct process *copy, *tmpsrc, *tmp, *beforehighest;
     
    printf("Starting Up:\tPriority Schedule\n");
     
    /* Duplicate process list */
    tmpsrc = proc;
    copy = tmp = NULL;
    while (tmpsrc != NULL) {
    if (copy == NULL) {
    copy = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
    tmp = copy;
    } else {
    tmp->next = init_process(tmpsrc->pid, tmpsrc->burst, tmpsrc->priority);
    tmp = tmp->next;
    };
    tmpsrc = tmpsrc->next;
    };
     

    time = 0;
    while (copy != NULL) {
    beforehighest = NULL;
    highest = copy->priority;
    tmp = copy->next;
    tmpsrc = copy;
    while (tmp != NULL) {
    if (tmp->priority < highest) {
    highest = tmp->priority;
    beforehighest = tmpsrc;
    };
    tmpsrc = tmp;
    tmp = tmp->next;
    };
    if (beforehighest == NULL) {
    start = time;
    time += copy->burst;
    end = time;
    printf("Process: %d\t\nStopping Time: %d\t\nTime Spent Waiting: %d\t\n\n", copy->pid, time, start);
    tmpsrc = copy->next;
    free(copy);
    copy = tmpsrc;
    } else {
    tmp = beforehighest->next;
    start = time;
    time += tmp->burst;
    end = time;
    printf("Process: %d\t\nStopping Time: %d\t\nTime Spent Waiting: %d\t\n\n", tmp->pid, time, start);
    beforehighest->next = tmp->next;
    free(tmp);
    };
    };
     
    printf("Shutting Down:\tPriority scheduling simulation\n");
    };
Exemplo n.º 2
0
void start(uint32_t* modulep, void* physbase, void* physfree)
{
	struct smap_t {
		uint64_t base, length;
		uint32_t type;
	}__attribute__((packed)) *smap;
	while(modulep[0] != 0x9001) modulep += modulep[1]+2;
	int i=0;
	bitmap_init(physfree);
	for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) {
		if (smap->type == 1 /* memory */ && smap->length != 0) {
//			printf("Available Physical Memory [%x-%x]\n", smap->base, smap->base + smap->length);
		        mem_track_init(smap->base, smap->length, physfree);
			i++;
		}
	}
//	printf("tarfs in [%p:%p]\n", &_binary_tarfs_start, &_binary_tarfs_end);
//	printf("Physbase and Physfree is: %p - %p\n", physbase, physfree);
	// kernel starts here
	set_kernel_video_page();
	kmalloc_bump_ptr += (uint64_t)kern_max;
	init_tarfs();
	init_process();

	printf("After init proc\n");
	printf("BACK IN MAIN\n");
	while(1);
}
Exemplo n.º 3
0
int main(void)
{    
    init_global();

    init_gdt();

    init_idt();

    init_tss();

    init_virtual_memory_mapping();

    init_process();

    init_8259a();

    init_clock();

    init_keyboard();

    init_syscall();

    debug_helper();

    restart();
}
Exemplo n.º 4
0
static void init()
{
    ::setlocale(LC_ALL, "");

    int32_t cpus = 0;

    process_base::cwd(s_root);

    os_base::cpuNumbers(cpus);
    if (cpus < 2)
        cpus = 2;

    exlib::Service::init(cpus + 1);

    init_date();
    init_acThread();
    init_aio();
    init_process();

#ifdef Linux
    init_sym();
#endif

    srand((unsigned int)time(0));

    v8::Platform* platform = v8::platform::CreateDefaultPlatform();
    v8::V8::InitializePlatform(platform);

    v8::V8::Initialize();
}
Exemplo n.º 5
0
int main(void) {
	struct Process procs[NUM_STACKS];
	unsigned int num_procs = 0; /* the next available stack. n should never be >= NUM_STACKS */
	unsigned int active_proc = 0;
	unsigned int val; /* interrupt condition */

	/* initialize the hardware timer */
	*(PIC + VIC_INTENABLE) = PIC_TIMER01;
	*TIMER0 = 10000;
	*(TIMER0 + TIMER_CONTROL) = TIMER_EN | TIMER_32BIT | TIMER_PERIODIC | TIMER_INTEN;

	/* start running tasks */
	procs[num_procs].stackptr = init_process(&(procs[num_procs]),STACK_SIZE,&first_task);
	num_procs++;
	while(1) {
		/* choose a process to run */
		active_proc = scheduler(procs, num_procs, active_proc); 
		/* run the process for some time */
		/* bwputs("activate\n"); */
		procs[active_proc].stackptr = activate(procs[active_proc].stackptr);

		/* handle the interrupt */
		val = procs[active_proc].stackptr[2+7]; /* the interrupt value */
		if(val == (unsigned int)PIC) {
			/* bwputs("hardware interrupt\n"); */
			if(*PIC & PIC_TIMER01) {
				if(*(TIMER0 + TIMER_MIS)) {
					/* bwputs("  timer0\n"); */
					*(TIMER0 + TIMER_INTCLR) = 1;
				}
			}
		} else if(val == (unsigned int)&yield) {
			/* bwputs("yield\n"); */
		} else if(val == (unsigned int)&fork) {
			num_procs = _fork(procs, active_proc, num_procs);
			bwputs("fork\n");
		} else if(val == (unsigned int)&write) {
			bwputs("write ");
			val = procs[active_proc].stackptr[2+0]; /* pid of receiver */
			if(_write(&(procs[active_proc]),&(procs[val]))) {
				bwputs("-> blocked\n");
			} else {
				bwputs("-> success\n");
			}
		} else if(val == (unsigned int)&read) {
			bwputs("read ");
			if(_read(&(procs[active_proc]))) {
				bwputs("-> blocked\n");
			} else {
				bwputs("-> success\n");
			}
		} else if(val == (unsigned int)&getpid) {
			procs[active_proc].stackptr[2+0] = active_proc;
		} else {
			bwputs("UNKNOWN SYSCALL\n");
		}
	}
	return 0;
}
Exemplo n.º 6
0
/**
 * Allocate arguments to different processes
 * Perform piping if necessary
 * Mark processes as background or foreground
 * Return TRUE if error, FALSE if no error
 */
int allocate_args(int argc, char **bufargs, struct Command *cmd) {
    struct Process *proc = cmd->procHead;
    int i = 0;
    int j = 0;
    int fd[2];
    static char devnull[] = "/dev/null";

    /* Split bufargs into process args */
   while (bufargs[i] != ARR_END) {

       if (bufargs[i][0] == '|' && bufargs[i][1] == '\0') {
           /* pipe between processes */
           proc->argsv[j] = ARR_END;
           proc->next = init_process(argc * sizeof(char *));

           if (pipe(fd) < 0) {
               perror("pipe failed");
               exit(ERR_PIPE);
           }

           /* Update process and cmd */
           proc->fdout = fd[WRITE_END];
           proc->next->fdin = fd[READ_END];

           proc = proc->next;
           cmd->runningProcs++;
           j = 0;

       } else if (bufargs[i][0] == '<' && bufargs[i][1] == '\0') {
           /* Set file for input redirection */
           i++;
           proc->filein = bufargs[i];
       } else if (bufargs[i][0] == '>' && bufargs[i][1] == '\0') {
           /* Set file for input redirection */
           i++;
           proc->fileout = bufargs[i];
       } else if (bufargs[i][0] == '&' && bufargs[i][1] == '\0') {
           /* Set command for backgrounding */
           if (bufargs[i+1] == ARR_END) {
               cmd->type = BG;
               if (cmd->procHead->filein == NULL) {
                   cmd->procHead->filein = devnull;
               }
           } else {
               printf("invalid background command\r\n");
               return TRUE;
           }
       } else {
           /* copy buffer across to process */
           proc->argsv[j] = bufargs[i];
           proc->argsv[++j] = ARR_END;
       }

       i++;
   }
   proc->argsv[j] = ARR_END;

   return FALSE;
}
Exemplo n.º 7
0
void 
monitor_init_process(const char* name, int* argc, char** argv, 
		     const unsigned pid)
{
  hpcrun_cmd = name;  /* command is also in /proc/pid/cmdline */
  if (opt_debug >= 1) {
    fprintf(stderr, "Init process callback from monitor received\n");
  }
  init_process();
}
Exemplo n.º 8
0
CManager::CManager() {
    m_vpart.clear();
    std::vector<CPartition>(m_vpart).swap(m_vpart);
    m_filepath = "Configuration/Config.txt";
    m_compath = "Configuration/Communication.txt";


    init_process();
    create_part();
}
    int main (void) {
    /* Initialize process list */
   
	printf("Process List Created\n");
    plist = init_process(1, 50, 3);
    plist->next = init_process(2, 1, 1); ptmp = plist->next; // pid, burst time, priotrity
	for (int i = 3; i < 47; i++){
ptmp->next = init_process(i,i%6 , newRandomDouble(1, 17)); ptmp = ptmp->next;
	}
    ptmp->next = init_process(48, 5, 2); // ends the data
	printf("Process List has Been Loaded with Processes\n");
	processQueueMethods();
    while (plist != NULL) {
    ptmp = plist;
    plist = plist->next;
    free(ptmp);
    };
	printf("Shutting Down Schedule Queue Simulation Program\n");
    return(0);
    };
Exemplo n.º 10
0
void kernel_main()
{
    init_process();
    init_dispatcher();
    init_ipc();
    init_interrupts();
    init_null_process();
    init_timer();
    init_com();
    init_keyb();
	init_ne2k();
    init_shell();

    while (1);
}
Exemplo n.º 11
0
void *producer_function(void *arg){
    int num_processes = (int) arg;
    int cpu_num = 0;
    process_info_t process;
    cpu_queue_t * process_queue;
    printf("Hi i'm the producer\n");

    for(int i = 0; i < num_processes; i ++) {
        process = init_process();

        if(cpu_num >= NUM_OF_CPU)
            cpu_num = 0;
        
        process.last_cpu = cpu_num;

        //CRITICAL SECTION
        pthread_mutex_lock(&cpus[cpu_num].mutex);

        if (process.dynamic_priority < 100)
            process_queue = &cpus[cpu_num].ready_queue[0];
        else
            process_queue = &cpus[cpu_num].ready_queue[1];

        if(process_queue->size == process_queue->capacity) {
            pthread_mutex_unlock(&cpus[cpu_num].mutex);
            printf("CPU %d full\n", cpu_num);
            cpu_num++;
            i--;
            continue;
        }
        process_queue->queue[process_queue->tail] = process;
        process_queue->tail = (process_queue->tail + 1) % Q_CAPACITY;
        cpus[cpu_num].size++;
        process_queue->size++;

        printf("Process with id: %d, static priority: %d, and schedule type of %d put in cpu: %d\n",
               process.pid,
               process.static_priority,
               process.scheduling_type,
               cpu_num);
        pthread_mutex_unlock(&cpus[cpu_num].mutex);
        cpu_num++;
    }

    thread_finished = 1;
    printf("Producer Exiting\n");
    pthread_exit(NULL);
}
Exemplo n.º 12
0
static int test_initfree_env(void)
{
   process_t         child = process_FREE;
   process_result_t  result;

   TEST(0 == init_process(&child, &childprocess_environment, 0, &(process_stdio_t)process_stdio_INIT_INHERIT));
   TEST(0 == wait_process(&child, &result));
   TEST(0 == free_process(&child));
   TEST(process_state_TERMINATED == result.state);
   TEST(0 == result.returncode);

   return 0 ;
ONERR:
   TEST(0 == free_process(&child));
   return EINVAL ;
}
Exemplo n.º 13
0
/**
 * Process the buffer
 * Return TRUE to exit program
 */
int process_buf(char **bufargs) {
    struct Command *cmd;
    int argc = 0;

    /*  cd command*/
    if (!strcmp(bufargs[0], "cd") && bufargs[0][2] == '\0') {
        set_cwd(bufargs[1]);
        return FALSE;
    }

    /* exit command */
    if (!strcmp(bufargs[0], "exit") && bufargs[0][4] == '\0') {
        return TRUE;
    }

    /* Get argc */
    while (bufargs[argc++] != ARR_END);

    /* Set up command and first process */
    cmd = init_command();
    cmd->procHead = init_process(argc * sizeof(char *));
    cmd->runningProcs++;

    /* Allocate arguments to their processes within the command */
    if (allocate_args(argc, bufargs, cmd) == TRUE) {
        /* Invalid command */
        free_command(NULL, cmd);
        return FALSE;
    }

    /* Add the command to the global commands */
    add_global(cmd);

    /* For each process in the command, fork it and set it up as running */
    fork_command(cmd);

    /* If foreground command, then wait on processes */
    if (cmd->type == FG) {
        wait_running(cmd);

        /* set the foreground command to null and clean it */
        globalCmd[FG] = NULL;
        free_command(NULL, cmd);
    }

    return FALSE;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    printf("process: %s version: %s, compile date: %s %s\n", __process__, __version__, __DATE__, __TIME__);

    if (argc < 2) {
        printf("usage: %s config.json\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    if (process_exist(__process__) != 0) {
        printf("process: %s exist\n", __process__);
        exit(EXIT_FAILURE);
    }

    int ret;
    ret = init_config(argv[1]);
    if (ret < 0) {
        error(EXIT_FAILURE, errno, "load config fail: %d", ret);
    }
    ret = init_process();
    if (ret < 0) {
        error(EXIT_FAILURE, errno, "init process fail: %d", ret);
    }
    ret = init_log();
    if (ret < 0) {
        error(EXIT_FAILURE, errno, "init log fail: %d", ret);
    }

    daemon(1, 1);
    process_keepalive();

    ret = init_server();
    if (ret < 0) {
        error(EXIT_FAILURE, errno, "init server fail: %d", ret);
    }

    nw_timer_set(&cron_timer, 0.5, true, on_cron_check, NULL);
    nw_timer_start(&cron_timer);

    log_vip("server start");
    log_stderr("server start");
    nw_loop_run();
    log_vip("server stop");

    return 0;
}
Exemplo n.º 15
0
int main()
{
/*	const extern u32 _KERNEL_START[],_KERNEL_END[];
	const extern u32 K_CODE_SEL[], K_DATA_SEL[];
	const extern u32 _KERNEL_TEXT_START[],_KERNEL_TEXT_END[];
	const extern u32 _KERNEL_DATA_START[],_KERNEL_DATA_END[];
	const extern u32 _KERNEL_BSS_START[],_KERNEL_BSS_END[]; */

	tty_cls();

	banner();

	/*if(TEST_BIT(K_MULTIBOOT_INFO->flags,MBI_FLAGS_MMAP)){
		kprintf("MMAP Present: 0x%x\n",K_MULTIBOOT_INFO->mmap_addr);

		memory_map_t *mmap;
		for(mmap=(memory_map_t *)K_MULTIBOOT_INFO->mmap_addr;
			(u32)mmap<K_MULTIBOOT_INFO->mmap_addr + K_MULTIBOOT_INFO->mmap_length;
			mmap=(memory_map_t *)((u32)mmap+mmap->size+sizeof(mmap->size))){
			kprintf("[%d] addr=0x%x-0x%x\n",mmap->type,mmap->base_addr_low,(mmap->base_addr_low+mmap->length_low));

		}
	}*/

	kprintf(" > Initialising system services...\n");
	init_interrupts();
	init_paging();
	init_heap();
	set_cpu_caps();
	init_pic();
	init_timer();
	init_process();

	kprintf(" > Enabling kernel preemption...\n");
	enable_kernel_preempt();
	enable_ints();
	
	kprintf(" > Spawning core process...\n");

	create_process("core",NULL,&core);


	/* We may get to here for a very short amount of time while we enable preemption */
	while(1);
}
Exemplo n.º 16
0
int
create_process(func_t* f, unsigned size, int period, int calcul)
{
  struct pcb_s *pcb;
  pcb = (struct pcb_s*) malloc_alloc(sizeof(struct pcb_s));

  if(!pcb)
    return 0;

  if (! ready_queue) {/* First process */
    ready_queue = pcb;
  } else {
    pcb->next = ready_queue->next;
  }
  
  ready_queue->next = pcb;
  return init_process(pcb,size,f,period,calcul);
}
Exemplo n.º 17
0
void kernel_main() {
    init_process();
    init_dispatcher();
    init_ipc();
    init_interrupts();
    init_null_process();
    init_timer();
#if VGA_MODE_ENABLED
    init_vga_mode();
#endif
    init_com();
    init_keyb();
    clear_kernel_window();
    init_ne_driver();
    init_em();
    init_shell();
    while (1);
}
Exemplo n.º 18
0
int main(int argc, char **argv){
    char addr[32];

    init_options();
    parse_options(argc, argv);

    if (GlobalArgs.helpflag || GlobalArgs.dbname == NULL){
	metadatadb_usage();
	return 0;
    }

    /* init daemon */ 
    init_process();
    
    /* init zeromq */ 
    void *ctx = zmq_init(1);
    if (ctx == NULL){
	syslog(LOG_CRIT,"MAIN ERROR: unable to init zmq context");
	exit(1);
    }

    snprintf(addr, 32, "tcp://*:%d", GlobalArgs.port);
    void *clients_skt = socket_bind(ctx, ZMQ_XREP, addr);
    if (clients_skt == NULL){
	syslog(LOG_CRIT,"MAIN ERROR: unable to bind skt to %s", addr);
	exit(1);
    }

    void *workers_skt = socket_bind(ctx, ZMQ_XREQ, "inproc://pipe");
    if (workers_skt == NULL){
	syslog(LOG_CRIT,"MAIN ERROR: unable to bind workers skt");
	exit(1);
    }

    unsigned int i;
    pthread_t worker_thr;
    for (i=0;i < GlobalArgs.nbthreads;i++){
	assert(pthread_create(&worker_thr, NULL, dowork, ctx) == 0);
    }

    assert(zmq_device(ZMQ_QUEUE, clients_skt, workers_skt) == 0);

    return 0;
}
Exemplo n.º 19
0
int main(int argc, char *argv[]) {
	//check for correct usage
	if (argc < 2) {
		printf("The correct usage is ./proja <filename>\n");
		perror("Incorrect usage of program!! exiting!!\n");
		return -1;
	}

	init_process();

	char *filename = argv[1];

	//1. read the input parameter file
	read_input_file(filename);
	sleep(2);//to see if that helps the last client being stuck at infinite loop

	destroy_process();
	return 0;
}
Exemplo n.º 20
0
static void init_ready_queue(FILE *ptr_file, queue *q_ready)
{
	char buffer[256];
	char **token_arr;
	int pid = -1;
	int new_proc_found = FALSE;
	while (fgets(buffer, 256, ptr_file) != NULL) {		/* read each string in the input file pointed to by ptr_file */
		token_arr = tokenize_str(buffer);		/* break the input string in the buffer into tokens */
		if (new_proc_found) {				/* check if an "ID #" command has been scanned */
			init_process(ptr_file, token_arr, q_ready, pid);	/* introduce a new process to the system */
			new_proc_found = FALSE;
		}
		if (is_new_proc(token_arr)) {			/* check if the token_arr contains an "ID #" command */
			new_proc_found = TRUE;
			pid = atoi(token_arr[1]);		/* record the PID parsed from the "ID #" command */
		}
		free_token(token_arr);
	}
	return;
}
Exemplo n.º 21
0
void Engine::init(void)
{
    if (!m_ready) {
        mutex_locker_t locker(m_lock);

        if (!m_ready) {
            // start process if not done yet
            if (m_process == 0) {
                init_process();
            }

            // load penging images
            load_libraries();

            // and (re)build pointer table
            init_ptr_data();

            // it is ready now
            m_ready = true;
        }
    }
}
Exemplo n.º 22
0
int main(int argc, char **argv){
    init_options();
    parse_options(argc, argv);

    if (GlobalArgs.helpflag || !GlobalArgs.index_name || !GlobalArgs.server_address){
	tableserver_usage();
	return 0;
    }

    /* init daemon */ 
    init_process();
 
    if (init_index() < 0){
	syslog(LOG_CRIT,"MAIN ERR: unable to init index");
	exit(1);
    }
    
    void *ctx = zmq_init(1);
    if (!ctx){
	syslog(LOG_CRIT,"MAIN ERR: unable to init zmq ctx");
	exit(1);
    }

    /* save to global variable to be used in signal handler */
    main_ctx = ctx;

    if (init_server(ctx) < 0){
	syslog(LOG_CRIT,"MAIN ERR: unable to init server");
	exit(1);
    }

    subscriber(ctx);
    
    zmq_term(ctx);
    return 0;
}
Exemplo n.º 23
0
void test_reset()
{
    asm("cli");
    interrupts_initialized = FALSE;

    lib_clear_window(kernel_window);

    test_result = 0;

    init_process();
    init_dispatcher();
    init_ipc();

    /*
     * Normally we would call the following init_*(), but the way some
     * test cases are written, this would disrupt them. So we manually
     * call them when we know it is OK.
     */
//    init_interrupts();
//    init_null_process();
//    init_timer();
//    init_com();
    
}
Exemplo n.º 24
0
int cdecl frotz_main (void)
{

    os_init_setup ();

    init_buffer ();

    init_err ();

    init_memory ();

    init_process ();

    init_sound ();

    os_init_screen ();

    init_undo ();

    z_restart ();

    interpret ();

    script_close ();

    record_close ();

    replay_close ();

    reset_memory ();

    os_reset_screen ();

    return 0;

}/* main */
Exemplo n.º 25
0
/* ARGSUSED */
int
main (int argc, char **argv, char **envp)
{
  int skip_args = 0;

#ifdef HAVE_PERSONALITY_LINUX32
  /* See if there is a gap between the end of BSS and the heap.
     In that case, set personality and exec ourself again.  */
  if (!initialized
      && strcmp (argv[argc-1], "dump") == 0
      && !getenv ("EMACS_HEAP_EXEC"))
    {
      /* Set this so we only do this once.  */
      putenv ("EMACS_HEAP_EXEC=true");

      /* A flag to turn off address randomization which is introduced
	 in linux kernel shipped with fedora core 4 */
      personality (PER_LINUX32 | ADDR_NO_RANDOMIZE);

      execvp (argv[0], argv);

      /* If the exec fails, try to dump anyway.  */
      perror ("execvp");
    }
#endif /* HAVE_PERSONALITY_LINUX32 */
 
/* Map in shared memory, if we are using that.  */
#ifdef HAVE_SHM
  if (argc > 1 && !strcmp (argv[1], "-nl"))
    {
      map_in_data (0);
      /* The shared memory was just restored, which clobbered this.  */
      skip_args = 1;
    }
  else
    {
      map_in_data (1);
      /* The shared memory was just restored, which clobbered this.  */
      skip_args = 0;
    }
#endif

#ifdef VMS
  /* If -map specified, map the data file in */
  if (argc > 2 && ! strcmp (argv[1], "-map"))
    {
      skip_args = 2;
      mapin_data (argv[2]);
    }

#ifdef LINK_CRTL_SHARE
#ifdef SHAREABLE_LIB_BUG
  /* Bletcherous shared libraries! */
  if (!stdin)
    stdin = fdopen (0, "r");
  if (!stdout)
    stdout = fdopen (1, "w");
  if (!stderr)
    stderr = fdopen (2, "w");
  if (!environ)
    environ = envp;
#endif /* SHAREABLE_LIB_BUG */
#endif /* LINK_CRTL_SHARE */
#endif /* VMS */
/* 92.11.4, 93.2.17 by M.Higashida */
#if defined(MSDOS) && defined(EMX)
  environ = envp;
#endif
#ifdef WIN32
  environ = envp;
#endif
/* end of patch */

#ifdef USG_SHARED_LIBRARIES
  if (bss_end)
    brk (bss_end);
#endif

#ifdef NeXT
  extern int malloc_cookie;

  /* This helps out unexnext.c.  */
  if (initialized) {
    if (malloc_jumpstart (malloc_cookie) != 0)
      fatal("malloc jumpstart failed!\n");
  } else {
    emacszone = NXCreateZone(ZONESIZE*vm_page_size,vm_page_size,1);
    if(emacszone == NX_NOZONE)
      fatal("can't create emacs zone.\n");
  }
#endif /* NeXT */

  clearerr (stdin);

#ifdef APOLLO
#ifndef APOLLO_SR10
  /* If USE_DOMAIN_ACLS environment variable exists,
     use ACLs rather than UNIX modes. */
  if (egetenv ("USE_DOMAIN_ACLS"))
    default_acl (USE_DEFACL);
#endif
#endif /* APOLLO */

#ifndef SYSTEM_MALLOC
  /* Arrange for warnings when nearly out of space.  */
  malloc_init (0, malloc_warning);
#endif

/* 91.10.16 by S.Hirano */
#if defined(MSDOS) && defined(GO32)
  _fmode = O_BINARY;	/* all of files are treated as binary files */
  (stdin)->_flag &= ~_IOTEXT;   /* also binary for stdio */
  (stdout)->_flag &= ~_IOTEXT;
  (stderr)->_flag &= ~_IOTEXT;
#endif /* MSDOS */
/* end of patch */

#ifdef HIGHPRI
  setpriority (PRIO_PROCESS, getpid (), HIGHPRI);
  setuid (getuid ());
#endif

  inhibit_window_system = 0;

/* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */
#if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32)
  xargv = argv;
  xargc = argc;
#endif

/* Handle the -t switch, which specifies filename to use as terminal */
  if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t"))
    {
      skip_args += 2;
      close (0);
      close (1);
      open (argv[skip_args], O_RDWR, 2 );
      dup (0);
      fprintf (stderr, "Using %s\n", argv[skip_args]);
/* 92.3.31 by K.Handa, 92.10.21 by M.Higashida */
#if defined (HAVE_X_WINDOWS) || defined (HAVE_SUN_CONSOLE) || (defined(MSDOS) && defined(HAVE_VGA_ADAPTER)) || defined (WIN32)
      inhibit_window_system = 1;	/* -t => -nw */
#endif
    }
#ifdef HAVE_X_WINDOWS
/* Handle the -d switch, which means use a different display for X */
  if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-d") ||
			       !strcmp (argv[skip_args + 1], "-display")))
    {
      skip_args += 2;
      alternate_display = argv[skip_args];
    } 
  else
    alternate_display = 0;
#endif	/* HAVE_X_WINDOWS */
/* 92.3.31 by K.Handa */
#ifdef HAVE_SUN_CONSOLE
  if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-sun"))) {
    extern Pixrect *screen;

    inhibit_window_system = -1;
    skip_args++;
    alternate_display = "/dev/fb";
    if (skip_args + 2 < argc && (!strcmp (argv[skip_args + 1], "-fb"))) {
      skip_args += 2;
      alternate_display = argv[skip_args];
    }
    if (screen = pr_open(alternate_display)) /* Just a test. */
      pr_close(screen);
    else
      alternate_display = 0;
  }
#endif /* HAVE_SUN_CONSOLE */
/* end of patch */
/* 92.10.17, 93.2.17 by M.Higashida */
#if defined(MSDOS) && defined(HAVE_VGA_ADAPTER)
  if (skip_args + 1 < argc && (!strcmp (argv[skip_args + 1], "-vga"))) {
    inhibit_window_system = -1;
    skip_args++;
  }
#endif /* MSDOS and HAVE_VGA_ADAPTER */
#ifdef WIN32
  inhibit_window_system = -1;
#endif
/* end of patch */
  if (skip_args + 1 < argc
      && (!strcmp (argv[skip_args + 1], "-nw")))
    {
      skip_args += 1;
      inhibit_window_system = 1;
    }

/* Handle the -batch switch, which means don't do interactive display.  */
  noninteractive = 0;
  if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch"))
    {
      skip_args += 1;
      noninteractive = 1;
    }

#ifdef POSIX_SIGNALS
  init_signals ();
#endif

#ifdef HAVE_TZSET
  /* Reinitialize the time zone if it was initialized before dumping Emacs.  */
  if (initialized)
    tzset ();
#endif
#ifdef WIN32 /* 93.2.25 by M.Higashida */
  _tzset ();
#endif

  if (
#ifndef CANNOT_DUMP
      ! noninteractive || initialized
#else
      1
#endif
      )
    {
      /* Don't catch these signals in batch mode if not initialized.
	 On some machines, this sets static data that would make
	 signal fail to work right when the dumped Emacs is run.  */
/* 91.10.16 by S.Hirano, 92.11.4 by M.Higashida */
#ifdef MSDOS
#ifdef GO32
      /* Nothing */
#else
#ifdef EMX
      signal (SIGBREAK, fatal_error_signal);
      signal (SIGQUIT, fatal_error_signal);
#endif
#endif
#else /* not MSDOS */
      signal (SIGHUP, fatal_error_signal);
      signal (SIGQUIT, fatal_error_signal);
      signal (SIGILL, fatal_error_signal);
      signal (SIGTRAP, fatal_error_signal);
      signal (SIGIOT, fatal_error_signal);
#ifdef SIGEMT
      signal (SIGEMT, fatal_error_signal);
#endif
      signal (SIGFPE, fatal_error_signal);
      signal (SIGBUS, fatal_error_signal);
      signal (SIGSEGV, fatal_error_signal);
      signal (SIGSYS, fatal_error_signal);
      signal (SIGTERM, fatal_error_signal);
#ifdef SIGXCPU
      signal (SIGXCPU, fatal_error_signal);
#endif
#ifdef SIGXFSZ
      signal (SIGXFSZ, fatal_error_signal);
#endif
#endif /* not MSDOS and GO32 */
/* end of patch */

#ifdef AIX
      /* This used to run fatal_error_signal,
	 but it isn't fatal.  There's nothing Emacs can usefully do.
	 Might as well let the system kill us if it insists.  */
      signal (SIGDANGER, SIG_IGN);
      signal (20, fatal_error_signal);
      signal (21, fatal_error_signal);
      signal (22, fatal_error_signal);
      signal (23, fatal_error_signal);
      signal (24, fatal_error_signal);
#ifdef SIGIO
      signal (SIGAIO, fatal_error_signal);
      signal (SIGPTY, fatal_error_signal);
#endif
#ifdef SIGURG
      /* Note that SIGIOINT is the same as SIGIO on some machines,
	 and the same as SIGURG on others.  It seems ore reliable to use the
	 name with a uniform meaning.  */
      signal (SIGURG, fatal_error_signal);
#endif
      signal (SIGGRANT, fatal_error_signal);
      signal (SIGRETRACT, fatal_error_signal);
      signal (SIGSOUND, fatal_error_signal);
      signal (SIGMSG, fatal_error_signal);
#endif /* AIX */
    }

  noninteractive1 = noninteractive;

/* Perform basic initializations (not merely interning symbols) */

  if (!initialized)
    {
      init_alloc_once ();
      init_obarray ();
      init_eval_once ();
      init_mc_once ();		/* 89.7.26, 91.10.19 by K.Handa */
      init_syntax_once ();	/* Create standard syntax table.  */
      init_category_once ();	/* 91.12.7 by K.Handa */
		      /* Must be done before init_buffer */
      init_buffer_once ();	/* Create buffer table and some buffers */
      init_minibuf_once ();	/* Create list of minibuffers */
			      /* Must precede init_window_once */
      init_window_once ();	/* Init the window system */
      /* 92.10.28 by M.Higashida */
#if defined (MSDOS) && defined (HAVE_VGA_ADAPTER)
      init_bdf_once ();		/* Init the BDF font structure. */
#endif
      /* end of patch */
    }

  init_alloc ();
#ifdef MAINTAIN_ENVIRONMENT
  init_environ ();
/* 92.3.25 by N.Hikichi */
#ifdef HAVE_X_WINDOWS
  if (alternate_display)
    set_environment_alist (build_string ("DISPLAY"),
			   build_string (alternate_display));
#endif /* HAVE_X_WINDOWS */
/* end of patch */
#endif
  init_codeconv ();		/* 92.1.7 by K.Handa */
  init_eval ();
  init_data ();
  init_read ();

  init_cmdargs (argc, argv, skip_args);	/* Create list Vcommand_line_args */
  init_buffer ();	/* Init default directory of main buffer */
  if (!noninteractive)
    {
#ifdef VMS
      init_vms_input ();/* init_display calls get_screen_size, that needs this */
#endif /* VMS */
      init_display ();	/* Determine terminal type.  init_sys_modes uses results */
    }
  init_keyboard ();	/* This too must precede init_sys_modes */
  init_callproc ();	/* And this too. */
  init_sys_modes ();	/* Init system terminal modes (RAW or CBREAK, etc.) */
  init_xdisp ();
  init_macros ();
  init_editfns ();
#ifdef VMS
  init_vmsfns ();
#endif /* VMS */
#ifdef subprocesses
  init_process ();
#endif /* subprocesses */

/* Intern the names of all standard functions and variables; define standard keys */

  if (!initialized)
    {
      /* The basic levels of Lisp must come first */
      /* And data must come first of all
	 for the sake of symbols like error-message */
      syms_of_data ();
      syms_of_alloc ();
#ifdef MAINTAIN_ENVIRONMENT
      syms_of_environ ();
#endif /* MAINTAIN_ENVIRONMENT */
      syms_of_read ();
      syms_of_print ();
      syms_of_eval ();
      syms_of_fns ();

      syms_of_abbrev ();
      syms_of_buffer ();
      syms_of_bytecode ();
      syms_of_callint ();
      syms_of_casefiddle ();
      syms_of_callproc ();
      syms_of_category ();	/* 91.11.11 by K.Handa */
      syms_of_codeconv ();	/* 92.1.7 by K.Handa */
      syms_of_cmds ();
#ifndef NO_DIR_LIBRARY
      syms_of_dired ();
#endif /* not NO_DIR_LIBRARY */
      syms_of_display ();
      syms_of_doc ();
      syms_of_editfns ();
      syms_of_emacs ();
      syms_of_fileio ();
#ifdef CLASH_DETECTION
      syms_of_filelock ();
#endif /* CLASH_DETECTION */
/* 92.11.1 by M.Higashida */
#ifdef FILE_TRANSLATION_MODE
      syms_of_transmode ();
#endif /* FILE_TRANSLATION_MODE */
/* end of patch */
      syms_of_indent ();
      syms_of_keyboard ();
      syms_of_keymap ();
      syms_of_macros ();
      syms_of_marker ();
      syms_of_minibuf ();
      syms_of_mocklisp ();
#ifdef subprocesses
      syms_of_process ();
#endif /* subprocesses */
      syms_of_search ();
      syms_of_syntax ();
      syms_of_undo ();
      syms_of_window ();
      syms_of_xdisp ();
#ifdef HAVE_X_WINDOWS
      syms_of_xfns ();
#ifdef HAVE_X_MENU
      syms_of_xmenu ();
#endif /* HAVE_X_MENU */
#endif /* HAVE_X_WINDOWS */
/* 87.6.8, 91.11.2, 92.3.31, 92.7.31  by K.Handa, 92.10.17, 93.2.17 by M.Higashida */
#ifdef HAVE_SUN_CONSOLE
      syms_of_sunterm ();
#endif
#if defined(MSDOS) && defined(HAVE_VGA_ADAPTER)
      syms_of_vgaterm ();
#endif
#ifdef WIN32
      syms_of_win32term ();
#endif
      syms_of_mc ();
      syms_of_ccl ();		/* 93.5.14 by K.Handa */
#ifdef WNN4
      syms_of_wnn ();
#endif
#ifdef CANNA
      syms_of_canna ();
#endif /* CANNA */
/* end of patch */

#ifdef MCPATH
      syms_of_mcpath ();
#endif /* MCPATH */

#ifdef SYMS_SYSTEM
      SYMS_SYSTEM;
#endif

#ifdef SYMS_MACHINE
      SYMS_MACHINE;
#endif

      keys_of_casefiddle ();
      keys_of_cmds ();
      keys_of_buffer ();
      keys_of_keyboard ();
      keys_of_keymap ();
      keys_of_macros ();
      keys_of_minibuf ();
      keys_of_window ();
    }

  if (!initialized)
    {
      /* Handle -l loadup-and-dump, args passed by Makefile. */
      if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l"))
	Vtop_level = Fcons (intern ("load"),
			    Fcons (build_string (argv[2 + skip_args]), Qnil));
#ifdef CANNOT_DUMP
      /* Unless next switch is -nl, load "loadup.el" first thing.  */
      if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl")))
	Vtop_level = Fcons (intern ("load"),
			    Fcons (build_string ("loadup.el"), Qnil));
#endif /* CANNOT_DUMP */
    }

  initialized = 1;

  /* Enter editor command loop.  This never returns.  */
  Frecursive_edit ();
  /* NOTREACHED */
}
Exemplo n.º 26
0
void runner::create_process() {
    //WaitForSingleObject(init_semaphore, INFINITE);

    if (process_status == process_spawner_crash) {
        ReleaseSemaphore(init_semaphore, 10, NULL);
        return;
    }
    ZeroMemory(&si, sizeof(si));

    si.cb = sizeof(si);
    {//if (!options.delegated) {//#TODO fix this
        si.dwFlags = STARTF_USESTDHANDLES;
        if (pipes.find(STD_OUTPUT_PIPE) != pipes.end())
            si.hStdOutput = pipes[STD_OUTPUT_PIPE]->get_pipe();
        if (pipes.find(STD_ERROR_PIPE) != pipes.end())
            si.hStdError = pipes[STD_ERROR_PIPE]->get_pipe();
        if (pipes.find(STD_INPUT_PIPE) != pipes.end())
            si.hStdInput = pipes[STD_INPUT_PIPE]->get_pipe();
    }
    si.lpDesktop = "";
    process_creation_flags = PROCESS_CREATION_FLAGS;

    if (options.hide_gui)
    {
        si.dwFlags |= STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_HIDE;
    }
    if (options.silent_errors) {
        SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
    }
    if (options.debug) {
        process_creation_flags |= DEBUG_PROCESS;
    }

    // Extracting program name and generating cmd line
    char *cmd;
    report.working_directory = options.working_directory;
    const char *wd = (options.working_directory != "")?options.working_directory.c_str():NULL;
    if (!wd)
    {
        char working_directory[MAX_PATH + 1];
        if (GetCurrentDirectoryA(MAX_PATH, working_directory))//error here is not critical
            report.working_directory = working_directory;
    }
    std::string run_program = program;

    std::string command_line;
    size_t  index_win = run_program.find_last_of('\\'),
        index_nix = run_program.find_last_of('/');

    if (index_win != std::string::npos) {
        command_line = run_program.substr(index_win + 1);
    } else if (index_nix != std::string::npos) {
        command_line = run_program.substr(index_nix + 1);
    } else {
        command_line = run_program;
    }

    command_line = command_line + " ";
    if (options.string_arguments == "") {
        command_line += options.get_arguments();
    } else {
        command_line += options.string_arguments;
    }
    cmd = new char [command_line.size()+1];
    strcpy(cmd, command_line.c_str());

    bool withLogon = options.login != "";

    if (withLogon) {
        report.login = a2w(options.login.c_str());
    } else {
        //IMPORTANT: if logon option selected & failed signalize it
        DWORD len = MAX_USER_NAME;
        wchar_t user_name[MAX_USER_NAME];
        if (GetUserNameW(user_name, &len)) {//error here is not critical
            report.login = user_name;
        }
    }

    running = withLogon ? init_process_with_logon(cmd, wd) : init_process(cmd, wd);

    ReleaseSemaphore(init_semaphore, 10, NULL);

    delete[] cmd;
}
Exemplo n.º 27
0
int main (
  int	argc,
  char	*argv[]
)
{
  pwr_tStatus	sts;
  int		event;
  plc_sProcess	*pp;
  uid_t         ruid;
  struct passwd *pwd;
/*
  struct rlimit rlim;
  int i;
*/  
  /* Set core dump file size limit to infinite */
/*
  rlim.rlim_cur =  RLIM_INFINITY;
  rlim.rlim_max =  RLIM_INFINITY;
  sts = setrlimit(RLIMIT_CORE, &rlim);
  printf("%d\n", sts);
  i = 1/0;
  printf("%d\n", i);
*/
  pp = init_process();

  qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcInit, qcom_cTmoEternal);

  init_plc(pp);
  create_threads(pp);
  init_threads(pp);

  /* Once threads has set their priority don't run as root */
  
#if 0
  ruid = getuid();
  
  if (ruid == 0) {
    pwd = getpwnam("pwrp");
    if (pwd != NULL) {
      setreuid(pwd->pw_uid, pwd->pw_uid);
    }
  }
  else 
    setreuid(ruid, ruid);
#endif

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInitDone);
  qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcStart, qcom_cTmoEternal);

//  proc_SetPriority(pp->PlcProcess->Prio);
  set_values(pp);
  start_threads(pp);
  run_threads(pp);
  time_Uptime(&sts, &pp->PlcProcess->StartTime, NULL);

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcStartDone);

#if 0
  /* Force the backup to take care initialized backup objects. */

  bck_ForceBackup(NULL);
#endif

  errh_SetStatus( PWR__SRUN);

  qcom_WaitOr(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_terminate | ini_mEvent_oldPlcStop, qcom_cTmoEternal, &event);

  switch ( event) {
  case ini_mEvent_terminate:
    errh_SetStatus( PWR__SRVTERM);

    stop_threads(pp);
    clean_all(pp);
    nmps_delete_lock( &sts);
    break;
  case ini_mEvent_oldPlcStop:
    errh_SetStatus( PWR__SRVTERM);

    time_Uptime(&sts, &pp->PlcProcess->StopTime, NULL);
    stop_threads(pp);
    save_values(pp);

    qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_oldPlcStopDone);

#if defined OS_ELN
    sts = proc_SetPriority(31);
#endif

    clean_all(pp);
    break;
  default: ;
  }

  exit(0);
}
Exemplo n.º 28
0
Arquivo: dsh.c Projeto: bsb20/dsh
bool readcmdline(char *msg) {
	
    print_colored_prompt(stdout, msg);

	char *cmdline = (char *)calloc(MAX_LEN_CMDLINE, sizeof(char));
	if(!cmdline)
		return invokefree(NULL, "malloc: no space");
	fgets(cmdline, MAX_LEN_CMDLINE, stdin);

	/* sequence is true only when the command line contains ; */
	bool sequence = false;
	/* seq_pos is used for storing the command line before ; */
	int seq_pos = 0;

	int cmdline_pos = 0; /*iterator for command line; */

	while(1) {
		job_t *current_job = find_last_job();
		int cmd_pos = 0; /* iterator for a command */
		int iofile_seek = 0; /*iofile_seek for file */
		bool valid_input = true; /* check for valid input */
		bool end_of_input = false; /* check for end of input */

		/* cmdline is NOOP, i.e., just return with spaces*/
		while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */
		if(cmdline[cmdline_pos] == '\n' || cmdline[cmdline_pos] == '\0' || feof(stdin))
			return false;
		
		if (cmdline[cmdline_pos] == '#') //no commands, just a comment
			return false;

                /* Check for invalid special symbols (characters) */
                if(cmdline[cmdline_pos] == ';' || cmdline[cmdline_pos] == '&'
                        || cmdline[cmdline_pos] == '<' || cmdline[cmdline_pos] == '>' || cmdline[cmdline_pos] == '|')
                        return false;

		char *cmd = (char *)calloc(MAX_LEN_CMDLINE, sizeof(char));
		if(!cmd)
			return invokefree(NULL,"malloc: no space");

		job_t *newjob = (job_t *)malloc(sizeof(job_t));
		if(!newjob)
			return invokefree(NULL,"malloc: no space");

		if(!first_job)
			first_job = current_job = newjob;
		else {
			current_job->next = newjob;
			current_job = current_job->next;
		}

		if(!init_job(current_job))
			return invokefree(current_job,"init_job: malloc failed");

		process_t *current_process = find_last_process(current_job);

		while(cmdline[cmdline_pos] != '\n' && cmdline[cmdline_pos] != '\0') {

			switch (cmdline[cmdline_pos]) {
								
			    case '<': /* input redirection */
				current_job->ifile = (char *) calloc(MAX_LEN_FILENAME, sizeof(char));
				if(!current_job->ifile)
					return invokefree(current_job,"malloc: no space");
				++cmdline_pos;
				while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */
				iofile_seek = 0;
				while(cmdline[cmdline_pos] != '\0' && !isspace(cmdline[cmdline_pos])){
					if(MAX_LEN_FILENAME == iofile_seek)
						return invokefree(current_job,"input redirection: file length exceeded");
					current_job->ifile[iofile_seek++] = cmdline[cmdline_pos++];
				}
				current_job->ifile[iofile_seek] = '\0';
				current_job->mystdin = INPUT_FD;
				while(isspace(cmdline[cmdline_pos])) {
					if(cmdline[cmdline_pos] == '\n')
						break;
					++cmdline_pos;
				}
				valid_input = false;
				break;
			
			    case '>': /* output redirection */
				current_job->ofile = (char *) calloc(MAX_LEN_FILENAME, sizeof(char));
				if(!current_job->ofile)
					return invokefree(current_job,"malloc: no space");
				++cmdline_pos;
				while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */
				iofile_seek = 0;
				while(cmdline[cmdline_pos] != '\0' && !isspace(cmdline[cmdline_pos])){
					if(MAX_LEN_FILENAME == iofile_seek) 
						return invokefree(current_job,"input redirection: file length exceeded");
					current_job->ofile[iofile_seek++] = cmdline[cmdline_pos++];
				}
				current_job->ofile[iofile_seek] = '\0';
				current_job->mystdout = OUTPUT_FD;
				while(isspace(cmdline[cmdline_pos])) {
					if(cmdline[cmdline_pos] == '\n')
						break;
					++cmdline_pos;
				}
				valid_input = false;
				break;

			   case '|': /* pipeline */
				cmd[cmd_pos] = '\0';
				process_t *newprocess = (process_t *)malloc(sizeof(process_t));
				if(!newprocess)
					return invokefree(current_job,"malloc: no space");
				if(!init_process(newprocess))
					return invokefree(current_job,"init_process: failed");
				if(!current_job->first_process)
					current_process = current_job->first_process = newprocess;
				else {
					current_process->next = newprocess;
					current_process = current_process->next;
				}
				if(!readprocessinfo(current_process, cmd))
					return invokefree(current_job,"parse cmd: error");
				++cmdline_pos;
				cmd_pos = 0; /*Reinitialze for new cmd */
				valid_input = true;	
				break;

			   case '&': /* background job */
				current_job->bg = true;
				while (isspace(cmdline[cmdline_pos])){++cmdline_pos;} /* ignore any spaces */
				if(cmdline[cmdline_pos+1] != '\n' && cmdline[cmdline_pos+1] != '\0')
					fprintf(stderr, "reading bg: extra input ignored");
				end_of_input = true;
				break;

			   case ';': /* sequence of jobs*/
				sequence = true;
				strncpy(current_job->commandinfo,cmdline+seq_pos,cmdline_pos-seq_pos);
				seq_pos = cmdline_pos + 1;
				break;	
                
			   case '#': /* comment */
				end_of_input = true;
				break;

			   default:
				if(!valid_input)
					return invokefree(current_job,"reading cmdline: could not fathom input");
				if(cmd_pos == MAX_LEN_CMDLINE-1)
					return invokefree(current_job,"reading cmdline: length exceeds the max limit");
				cmd[cmd_pos++] = cmdline[cmdline_pos++];
				break;
			}
			if(end_of_input || sequence)
				break;
		}
		cmd[cmd_pos] = '\0';
		process_t *newprocess = (process_t *)malloc(sizeof(process_t));
		if(!newprocess)
			return invokefree(current_job,"malloc: no space");
		if(!init_process(newprocess))
			return invokefree(current_job,"init_process: failed");

		if(!current_job->first_process)
			current_process = current_job->first_process = newprocess;
		else {
			current_process->next = newprocess;
			current_process = current_process->next;
		}
		if(!readprocessinfo(current_process, cmd))
			return invokefree(current_job,"read process info: error");
		if(!sequence) {
			strncpy(current_job->commandinfo,cmdline+seq_pos,cmdline_pos-seq_pos);
			break;
		}
		sequence = false;
		++cmdline_pos;
	}
	return true;
}
Exemplo n.º 29
0
int main(int argc, char **argv) {
    initialize_system();
    cmd_process_demo(0, NULL);
    init_process();
    return 0;
}
Exemplo n.º 30
0
COIPIPELINE Engine::get_pipeline(_Offload_stream handle)
{
    Stream * stream = Stream::find_stream(handle, false);

    if (!stream) {
        LIBOFFLOAD_ERROR(c_offload_no_stream, m_index);
        LIBOFFLOAD_ABORT;
    }

    COIPIPELINE pipeline = stream->get_pipeline();

    if (pipeline == 0) {
        COIRESULT     res;
        int           proc_num;
        COI_CPU_MASK  in_Mask ;

#ifndef TARGET_WINNT
        proc_num = __sync_fetch_and_add(&m_proc_number, 1);
#else // TARGET_WINNT
        proc_num = _InterlockedIncrement(&m_proc_number);
#endif // TARGET_WINNT

        if (proc_num > COI_PIPELINE_MAX_PIPELINES) {
            LIBOFFLOAD_ERROR(c_coipipe_max_number, COI_PIPELINE_MAX_PIPELINES);
            LIBOFFLOAD_ABORT;
        }

        m_stream_lock.lock();

        // start process if not done yet
        if (m_process == 0) {
            init_process();
        }

        // create CPUmask
        res = COI::PipelineClearCPUMask(in_Mask);
        check_result(res, c_clear_cpu_mask, m_index, res);

        int stream_cpu_num = stream->get_cpu_number();

        stream->m_stream_cpus.reset();

        int threads_per_core = m_num_threads / m_num_cores;

        // The "stream_cpu_num" available threads is set in mask.
        // Available threads are defined by examining of m_cpus bitset.
        // We skip thread 0 .
        for (int i = 1; i < m_num_threads; i++) {
            // for available thread i m_cpus[i] is equal to 1
            if (m_cpus[i]) {
                res = COI::PipelineSetCPUMask(m_process,
                    i / threads_per_core,
                    i % threads_per_core,
                    in_Mask);

                check_result(res, c_set_cpu_mask, res);
                // mark thread i as nonavailable
                m_cpus.set(i,0);
                // Mark thread i as given for the stream.
                // In case of stream destroying by call to
                // _Offload_stream_destroy we can mark the thread i as
                // available.
                stream->m_stream_cpus.set(i);
                if (--stream_cpu_num <= 0) {
                    break;
                }
            }
        }

        // if stream_cpu_num is greater than 0 there are not enough
        // available threads
        if (stream_cpu_num > 0) {
            LIBOFFLOAD_ERROR(c_create_pipeline_for_stream, m_num_threads);
            LIBOFFLOAD_ABORT;
        }
        // create pipeline for this thread
        OFFLOAD_DEBUG_TRACE(2, "COIPipelineCreate Mask\n"
                               "%016lx %016lx %016lx %016lx\n%016lx %016lx %016lx %016lx\n"
                               "%016lx %016lx %016lx %016lx\n%016lx %016lx %016lx %016lx\n",
                               in_Mask[0], in_Mask[1], in_Mask[2], in_Mask[3],
                               in_Mask[4], in_Mask[5], in_Mask[6], in_Mask[7],
                               in_Mask[8], in_Mask[9], in_Mask[10], in_Mask[11],
                               in_Mask[12], in_Mask[13], in_Mask[14], in_Mask[15]);
        res = COI::PipelineCreate(m_process, in_Mask,
                                  mic_stack_size, &pipeline);
        check_result(res, c_pipeline_create, m_index, res);

        // Set stream's affinities
        {
            struct affinity_spec affinity_spec;
            char* affinity_type;
            int i;

            // "compact" by default
            affinity_spec.affinity_type = affinity_compact;

            // Check if user has specified type of affinity
            if ((affinity_type = getenv("OFFLOAD_STREAM_AFFINITY")) !=
                                        NULL)
            {
                char affinity_str[16];
                int affinity_str_len;

                OFFLOAD_DEBUG_TRACE(2,
                    "User has specified OFFLOAD_STREAM_AFFINITY=%s\n",
                    affinity_type);

                // Set type of affinity requested
                affinity_str_len = strlen(affinity_type);
                for (i=0; i<affinity_str_len && i<15; i++)
                {
                    affinity_str[i] = tolower(affinity_type[i]);
                }
                affinity_str[i] = '\0';
                if (strcmp(affinity_str, "compact") == 0) {
                    affinity_spec.affinity_type = affinity_compact;
                    OFFLOAD_DEBUG_TRACE(2, "Setting affinity=compact\n");
                } else if (strcmp(affinity_str, "scatter") == 0) {
                    affinity_spec.affinity_type = affinity_scatter;
                    OFFLOAD_DEBUG_TRACE(2, "Setting affinity=scatter\n");
                } else {
                    LIBOFFLOAD_ERROR(c_incorrect_affinity, affinity_str);
                    affinity_spec.affinity_type = affinity_compact;
                    OFFLOAD_DEBUG_TRACE(2, "Setting affinity=compact\n");
                }
            }
            // Make flat copy of sink mask because COI's mask is opaque
            for (i=0; i<16; i++) {
                affinity_spec.sink_mask[i] = in_Mask[i];
            }
            // Set number of cores and threads
            affinity_spec.num_cores = m_num_cores;
            affinity_spec.num_threads = m_num_threads;

            COIEVENT event;
            res = COI::PipelineRunFunction(pipeline,
                                   m_funcs[c_func_set_stream_affinity],
                                   0, 0, 0,
                                   0, 0,
                                   &affinity_spec, sizeof(affinity_spec),
                                   0, 0,
                                   &event);
            check_result(res, c_pipeline_run_func, m_index, res);
    
            res = COI::EventWait(1, &event, -1, 1, 0, 0);
            check_result(res, c_event_wait, res);
        }

        m_stream_lock.unlock();
        stream->set_pipeline(pipeline);
    }
    return pipeline;
}