Changeset 93fb170c in mainline for uspace/app/killall/killall.c
- Timestamp:
- 2011-01-08T18:51:31Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 15be932
- Parents:
- 8f748215 (diff), a523af4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/killall/killall.c
r8f748215 r93fb170c 1 1 /* 2 * Copyright (c) 20 06 Ondrej Palkovsky2 * Copyright (c) 2010 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup killall 30 * @{ 31 */ 32 /** 33 * @file Forcefully terminate a task specified by name. 34 */ 35 36 #include <errno.h> 29 37 #include <stdio.h> 30 #include <unistd.h> 31 #include <atomic.h> 32 #include "../tester.h" 38 #include <task.h> 39 #include <stats.h> 40 #include <str_error.h> 41 #include <malloc.h> 33 42 34 static atomic_t finish; 43 #define NAME "killall" 35 44 36 static void callback(void *priv, int retval, ipc_call_t *data)45 static void print_syntax(void) 37 46 { 38 atomic_set(&finish, 1);47 printf("Syntax: " NAME " <task name>\n"); 39 48 } 40 49 41 const char *test_connect(void)50 int main(int argc, char *argv[]) 42 51 { 43 TPRINTF("Connecting to %u...", IPC_TEST_SERVICE); 44 int phone = ipc_connect_me_to(PHONE_NS, IPC_TEST_SERVICE, 0, 0); 45 if (phone > 0) { 46 TPRINTF("phoneid %d\n", phone); 47 } else { 48 TPRINTF("\n"); 49 return "ipc_connect_me_to() failed"; 52 if (argc != 2) { 53 print_syntax(); 54 return 1; 50 55 } 51 56 52 printf("Sending synchronous message...\n"); 53 int retval = ipc_call_sync_0_0(phone, IPC_TEST_METHOD); 54 TPRINTF("Received response to synchronous message\n"); 57 size_t count; 58 stats_task_t *stats_tasks = stats_get_tasks(&count); 55 59 56 TPRINTF("Sending asynchronous message...\n"); 57 atomic_set(&finish, 0); 58 ipc_call_async_0(phone, IPC_TEST_METHOD, NULL, callback, 1); 59 while (atomic_get(&finish) != 1) 60 TPRINTF("."); 61 TPRINTF("Received response to asynchronous message\n"); 62 63 TPRINTF("Hanging up..."); 64 retval = ipc_hangup(phone); 65 if (retval == 0) { 66 TPRINTF("OK\n"); 67 } else { 68 TPRINTF("\n"); 69 return "ipc_hangup() failed"; 60 if (stats_tasks == NULL) { 61 fprintf(stderr, "%s: Unable to get tasks\n", NAME); 62 return 2; 70 63 } 71 64 72 return NULL; 65 size_t i; 66 for (i = 0; i < count; i++) { 67 if (str_cmp(stats_tasks[i].name, argv[1]) == 0) { 68 task_id_t taskid = stats_tasks[i].task_id; 69 int rc = task_kill(taskid); 70 if (rc != EOK) 71 printf("Failed to kill task ID %" PRIu64 ": %s\n", 72 taskid, str_error(rc)); 73 else 74 printf("Killed task ID %" PRIu64 "\n", taskid); 75 } 76 } 77 78 free(stats_tasks); 79 80 return 0; 73 81 } 82 83 /** @} 84 */
Note:
See TracChangeset
for help on using the changeset viewer.