Пример #1
0
int main( int /* argc */, char * argv[] )
{
#ifndef _WIN32
	// Get the buffer file id and rtx pid as parameters.
	int buffer_file_id = 0 ;
	sscanf( argv[1], "%d", &buffer_file_id );
	sscanf( argv[2], "%d", &rtx_pid );

	// Check that a valid file id was passed.
	if ( buffer_file_id < 1 )
	{
		printf( "crt - An invalid file id was passed. Terminating\n" );
		terminate_process( 0 );
	}

	// Initialize the shared memory pointer to the same memory segment as the rtx did.
	sm_ptr = ( buffer * ) mmap( 0, sizeof( buffer ), PROT_READ | PROT_WRITE, MAP_SHARED, buffer_file_id, 0 );
	
	// Check whether the shared memory pointer was initialized correctly.
	if ( sm_ptr == NULL )
	{
		printf( "Unable to create shared memory for the crt for crt helper process\n" );
		terminate_process(0);
	}

	// Set the helper process to terminate when SIGINT is received.
	sigset( SIGINT, &terminate_process );
	
	// Set the helper process to output characters when RSIGCRTR is received.
	sigset( RSIGCRTR, &output_chars );

	// Enter infinite loop waiting for signal from rtx to output chars or terminate.
	while ( true ) {}
#endif
}
Пример #2
0
int main( int /* argc */, char * argv[] )
{
#ifndef _WIN32
 
	// Get the buffer file id and rtx pid as parameters.
	int buffer_file_id = 0;
	sscanf( argv[1], "%d", &buffer_file_id );
	sscanf( argv[2], "%d", &rtx_pid );
		
	// Check that a valid file id was passed.
	if ( buffer_file_id < 1 )
	{
		printf( "kbd - An invalid file id was passed. Terminating" );
		terminate_process( 0 );
	}
	
	// Initialize the shared memory pointer to the same memory segment as the rtx did.
	sm_ptr = ( buffer * ) mmap( NULL, sizeof( buffer ), PROT_READ | PROT_WRITE, MAP_SHARED, buffer_file_id, ( off_t ) 0 );

	// Check whether the shared memory pointer was initialized correctly.
	if ( sm_ptr == NULL )
	{
		printf( "kbd - Unable to create shared memory for the keyboard for keyboard helper process" );
		terminate_process( 0 );
	}

	// set the helper process to terminate when SIGINT is received.
	sigset( SIGINT, &terminate_process );

	// Enter an infinite loop to receive keyboad input.
	char c;
	int buffer_index = 0;
	while ( true )
	{
		// Get the first character from the keyboard since the last time the "return" key was pressed.
		c = getchar();

		// Check if the return key was pressed.
		if ( c != '\n' )
		{
			// If there is room in the buffer (leaving one extra space for the terminating character), then add it to the shared memory buffer.
			if ( buffer_index < BUFFER_SIZE - 1 )
				( * sm_ptr )[buffer_index++] = c;
		}
		else 
		{
			// Send RSIGKBD signal to rtx telling it to read buffer.
			( * sm_ptr )[buffer_index] = '\0';
			kill( rtx_pid, RSIGKBD );
			buffer_index = 0;	
		}
	}
#endif
}
Пример #3
0
// Attention! PID has a HANDLE type. But it still is PID.
VOID DDKAPI
create_process_watcher(HANDLE dwParentId, HANDLE dwProcessId, BOOLEAN create)
{
  DbgPrint("CP callback runned PID: %5d, Status: %s\r\n",
           dwProcessId, create ? "up" : "down");

  DWORD i;
  if (create)
    // Process creation is handled on load, not creation
    return;

  for (i = 0; i < ENT_CNT && g_proc_table[i].sl_pid != dwProcessId; ++i);
  if (i != ENT_CNT)
    g_proc_table[i].sl_pid = 0;

  for (i = 0; i < ENT_CNT && g_proc_table[i].pid != dwProcessId; ++i);
  if (i == ENT_CNT) {
    // The process is not in list
    return;
  }
  DWORD pid = g_proc_table[i].sl_pid;
  g_proc_table[i].pid = 0;
  g_proc_table[i].sl_pid = 0;
  terminate_process(pid);
  return;
}
Пример #4
0
int s2e_stop_chan (int chan)
{
    if (chan < 0 || chan >= S2E_CHAN_MAX)
    {
        return -1;
    }

    terminate_process (pid_files[chan], 1000, S2E_CMD_NAME);

    return 0;
}
Пример #5
0
//-------------------------------------------------------------------------
// Terminate TRK connection
void metrotrk_t::term(void)
{
  if ( tpi.pid != -1 )
  {
    terminate_process(tpi.pid);
    tpi.pid = -1;
  }
  if ( hp != INVALID_HANDLE_VALUE )
  {
    CloseHandle(hp);
    hp = INVALID_HANDLE_VALUE;
  }
}
Пример #6
0
Файл: run.c Проект: kmillar/rho
static void
rpipeTerminate(rpipe * r)
{
    if (r->thread) {
	TerminateThread(r->thread, 0);
	CloseHandle(r->thread);
	r->thread = NULL;
    }
    if (r->active) {
	terminate_process(&(r->pi));
	r->active = 0;
    }
}
Пример #7
0
NTSTATUS SERVICECALL
NtTerminateProcess(IN HANDLE ProcessHandle,
		IN NTSTATUS ExitStatus)
{
	struct eprocess *process;
	struct ethread *cur_thread;
	NTSTATUS status;

	ktrace("\n");

	if ((status = ref_object_by_handle(ProcessHandle ? ProcessHandle : NtCurrentProcess(),
				PROCESS_TERMINATE, 
				process_object_type, 
				get_pre_mode(), 
				(PVOID *) &process, 
				NULL)))
		return status;

	cur_thread = (struct ethread *) get_current_ethread();

	terminate_process(process->win32process, ExitStatus);
	release_object(process->win32process);

	lock_process(process);

	if (process->exit_time.quad) {
		unlock_process(process);
		deref_object(process);
		return STATUS_PROCESS_IS_TERMINATING;
	}

	query_sys_time(&process->exit_time);
	process->exit_status = (unsigned long)ExitStatus;

	unlock_process(process);
	deref_object(process);

	if (process == get_current_eprocess()) {
		cur_thread->exit_status = ExitStatus;
		do_group_exit((ExitStatus & 0xff) << 8);
	} else {
		struct ethread *first_thread = get_first_thread(process);

		first_thread->exit_status = ExitStatus;
		send_sig_info(SIGKILL, SEND_SIG_FORCED, first_thread->et_task->group_leader);
	}

	return STATUS_SUCCESS;
}
Пример #8
0
int
main(int argc, char **argv)
{
    int argidx=1;
    exe[0]=0;
    if (argc < 2) 
        usage();

    while (argidx < argc) {

	if (!strcmp(argv[argidx], "-help")) {
  	    help();
	}
	else if (!strcmp(argv[argidx], "-quiet")) {
	    killquietly=TRUE;
	}
	else if (!strcmp(argv[argidx], "-pid")) {
	    pid=atoi(argv[++argidx]);
	}
	else if (!strcmp(argv[argidx], "-exe")) {
	    _snwprintf(exe, MAX_PATH, L"%S", argv[++argidx]);
	}
	else if (!strcmp(argv[argidx], "-underdr")) {
            underdr=TRUE;
	}
	else if (!strcmp(argv[argidx], "-v")) {
#ifdef BUILD_NUMBER
	  printf("DRkill.exe build %d -- %s\n", BUILD_NUMBER, __DATE__);
#else
	  printf("DRkill.exe custom build -- %s, %s\n", __DATE__, __TIME__);
#endif
	}
	else {
	    fprintf(stderr,"Unknown option: %s\n", argv[argidx]);
	    usage();
	}
	argidx++;
    }
    
    if(pid) {
        if (!killquietly)
            printf("killing process %d\n", pid);

        terminate_process(pid);       
    }
    else {
        procwalk();
    }
}
Пример #9
0
int kill_process(process_t *proc)
{
    if ( proc == NULL || proc->state == PROCESS_TERMINATED)
    {
        return -ERR_SRCH;
    }
    if ( proc == curr_running_proc )
    {
        setcr3(phys_kernel_level4);
    }
    terminate_process(proc, 0);
    if ( curr_running_proc == NULL )
    {
        process_schedule();
    }
    return 0;
}
Пример #10
0
/* kill all processes being attached to a console renderer */
void kill_console_processes(struct w32thread *renderer, int exit_code)
{
	for (;;) { /* restart from the beginning of the list every time */
		struct w32process *process;

		/* find the first process being attached to 'renderer' and still running */
		LIST_FOR_EACH_ENTRY(process, &process_list, struct w32process, entry) {
			if (process == renderer->process)
				continue;
			if (!process->running_threads)
				continue;
			if (process->console && console_get_renderer(process->console) == renderer)
				break;
		}
		if (&process->entry == &process_list)
			break;  /* no process found */
		terminate_process(process, exit_code);
	}
}
Пример #11
0
void client_shutdown()
{
	console_print("Shutting down...\n");
	
	kill_servers();
	kill_download();
	kill_key();
	kill_openssl();
	kill_sound();
	kill_game();
	kill_network();
	kill_render();
//	kill_input();
	dump_console();
	kill_console();
	kill_control();
	write_config_file();
	
	SDL_Quit();

	terminate_process();
}
Пример #12
0
BOOL
pw_callback(process_info_t *pi, void **param)
{
    int res;

    if ((pid != 0 && pi->ProcessID == pid) ||
        (exe[0] != '\0' && !wcsicmp(exe, pi->ProcessName)) || 
        underdr) {

        res = under_dynamorio(pi->ProcessID);
        
        if (exe[0] != '\0' || pid != 0 ||
            (underdr && (res != DLL_NONE && res != DLL_UNKNOWN))) {

            if (!killquietly)
                printf("killing process %d=%S\n",
                       pi->ProcessID, pi->ProcessName);
            
            terminate_process(pi->ProcessID);
        }
    } 
    return TRUE;
}
Пример #13
0
int32_t handle_waiting_processes()
{
    process_t* start = process_waiting_queue;
    while(start != NULL)
    {
        if (start->flags & I_AM_SLEEPING )
        {
            if ( start->sleep_ticks == 0 )
            {
                start->flags ^= I_AM_SLEEPING;
                switch_process_queue(start, PROCESS_RUNNABLE_QUEUE);
            }
            else
            {
                start->sleep_ticks--;
            }
        }

        if (start->flags & ALARM_ACTIVATED)
        {
            if ( start->alarm_ticks == 0 )
            {
                if (start == curr_running_proc)
                {
                    // switch to kernel's cr3
                    setcr3(phys_kernel_level4);
                }
                terminate_process(start, 0);
                start->flags ^= ALARM_ACTIVATED;
            }
            else
            {
                start->alarm_ticks--;
            }
        }
        start = start->next;
    }

    // Handle Alarm which is with runnable processes
    start = process_runnable_queue;
    while(start != NULL)
    {
        if (start->flags & ALARM_ACTIVATED)
        {
            if ( start->alarm_ticks == 0 )
            {
                if (start == curr_running_proc)
                {
                    // switch to kernel's cr3
                    setcr3(phys_kernel_level4);
                }
                terminate_process(start, 0);
                start->flags ^= ALARM_ACTIVATED;
            }
            else
            {
                start->alarm_ticks--;
            }
        }
        start = start->next;
    }

     return 0;
}
Пример #14
0
int main()
{
	pthread_t tid1;
	pthread_attr_t attr;
	pthread_attr_init(&attr);
	int temp=0, n;
	pthread_create(&tid1, &attr, load_check, (void *)temp);

	int shmid1;
    	key_t key1;
    	char *shm1, *s1;
    	key1 = 5000;

    	if ((shmid1 = shmget(key1, MAX, IPC_CREAT | 0666)) < 0) 
	{
        	perror("shmget");
        	exit(1);
    	}
    	if ((shm1 = shmat(shmid1, NULL, 0)) == (char *) -1) 
	{
        	perror("shmat");
        	exit(1);
    	}

	char *str1 = "exit";
	char *str2;

	while(1)
	{
		if(*shm1=='^')
		{
			*shm1='@';
			while(*shm1=='@')
				sleep(1);				
			while(1)
			{				
				str2=shm1;					
				if((strncmp(str1,str2,4))==0)
				{
					break;
				}					
				for (s1 = shm1; *s1 != NULL; s1++)
        				putchar(*s1);
    				putchar('\n');
    				*shm1 = '*';
				while(*shm1=='*')
					sleep(1);				
			}
			*shm1='$';
		}				
		printf("Select an option\n1. View all running processes\n2. Duration from which a process is running\n3. CPU and memory utilization of all processes\n4. Terminate a process\n5. View all logged in users\n6. Logout an user\n7. Send message to all users\n8. Exit\n");
		scanf("%d", &n);
		switch(n)
		{
			case 1:
				view_processes();
				break;
			case 2:
				view_duration();
				break;
			case 3:
				view_utilization();
				break;		
			case 4:
				terminate_process();
				break;
			case 5:
				view_users();
				break;
			case 6:
				logout_user();				
				break;
			case 7:
				*shm1='^';
				while(*shm1 == '^')
					sleep(1);				
				while(*shm1 != '$')
				{
					s1 = shm1;
    					printf("Enter the message you want to send to all users\n");
					gets(s1);
    					while (*shm1 != '*' && *shm1 != '$')
        					sleep(1);
				}
				break;
			case 8:				
				return;				
				break;
		}
	}
	pthread_join(tid1,NULL);
}
Пример #15
0
void sys_terminate_process(proc_id pid)
{
	terminate_process(pid);
}