Index: uspace/app/trace/trace.c
===================================================================
--- uspace/app/trace/trace.c	(revision 2c57ee144b471022bccca5f06ef68134ccc17208)
+++ uspace/app/trace/trace.c	(revision 47e0a05baa886b025c008b7e51748be0a29cd784)
@@ -42,4 +42,5 @@
 #include <udebug.h>
 #include <async.h>
+#include <task.h>
 
 // Temporary: service and method names
@@ -129,5 +130,5 @@
 	printf("Threads:");
 	for (i = 0; i < n_threads; i++) {
-		printf(" [%d] (hash 0x%u)", 1+i, thread_hash_buf[i]);
+		printf(" [%d] (hash 0x%x)", 1+i, thread_hash_buf[i]);
 	}
 	printf("\ntotal of %u threads\n", tb_needed/sizeof(unsigned));
@@ -541,5 +542,7 @@
 static void print_syntax()
 {
-	printf("Syntax: trace [+<events>] <task_id>\n");
+	printf("Syntax:\n");
+	printf("\ttrace [+<events>] <executable> [<arg1> [...]]\n");
+	printf("or\ttrace [+<events>] -t <task_id>\n");
 	printf("Events: (default is +tp)\n");
 	printf("\n");
@@ -549,5 +552,7 @@
 	printf("\tp ... Protocol level\n");
 	printf("\n");
-	printf("Example: trace +tsip 12\n");
+	printf("Examples:\n");
+	printf("\ttrace +s /app/tetris\n");
+	printf("\ttrace +tsip -t 12\n");
 }
 
@@ -581,14 +586,29 @@
 	char *err_p;
 
+	task_id = 0;
+
 	--argc; ++argv;
 
-	while (argc > 1) {
+	while (argc > 0) {
 		arg = *argv;
 		if (arg[0] == '+') {
 			display_mask = parse_display_mask(&arg[1]);
+		} else if (arg[0] == '-') {
+			if (arg[1] == 't') {
+				/* Trace an already running task */
+				--argc; ++argv;
+				task_id = strtol(*argv, &err_p, 10);
+				if (*err_p) {
+					printf("Task ID syntax error\n");
+					print_syntax();
+					return -1;
+				}
+			} else {
+				printf("Uknown option '%s'\n", arg[0]);
+				print_syntax();
+				return -1;
+			}
 		} else {
-			printf("Unexpected argument '%s'\n", arg);
-			print_syntax();
-			return -1;
+			break;
 		}
 
@@ -596,17 +616,24 @@
 	}
 
-	if (argc != 1) {
+	if (task_id != 0) {
+		if (argc == 0) return;
+		printf("Extra arguments\n");
+		print_syntax();
+		return -1;
+	}
+
+	if (argc < 1) {
 		printf("Missing argument\n");
 		print_syntax();
-		return 1;
-	}
-
-	task_id = strtol(*argv, &err_p, 10);
-
-	if (*err_p) {
-		printf("Task ID syntax error\n");
-		print_syntax();
 		return -1;
 	}
+
+	/* Execute the specified command and trace the new task. */
+	printf("Spawning '%s' with arguments:\n", *argv);
+	{
+		char **cp = argv;
+		while (*cp) printf("'%s'\n", *cp++);
+	}
+	task_id = task_spawn(*argv, argv);
 
 	return 0;
Index: uspace/lib/libc/generic/task.c
===================================================================
--- uspace/lib/libc/generic/task.c	(revision 2c57ee144b471022bccca5f06ef68134ccc17208)
+++ uspace/lib/libc/generic/task.c	(revision 47e0a05baa886b025c008b7e51748be0a29cd784)
@@ -134,4 +134,5 @@
 	char *pa;
 	size_t pa_len;
+	task_id_t task_id;
 
 	pa = absolutize(path, &pa_len);
@@ -152,4 +153,16 @@
 		return 0;
 
+	/* Get task ID. */
+	req = async_send_0(phone_id, LOADER_GET_TASKID, &answer);
+	rc = ipc_data_read_start(phone_id, &task_id, sizeof(task_id));
+	if (rc != EOK) {
+		async_wait_for(req, NULL);
+		goto error;
+	}
+
+	async_wait_for(req, &retval);
+	if (retval != EOK)
+		goto error;
+
 	/* Send program pathname */
 	req = async_send_0(phone_id, LOADER_SET_PATHNAME, &answer);
@@ -176,5 +189,5 @@
 	/* Success */
 	ipc_hangup(phone_id);
-	return 1;
+	return task_id;
 
 	/* Error exit */
Index: uspace/lib/libc/include/ipc/loader.h
===================================================================
--- uspace/lib/libc/include/ipc/loader.h	(revision 2c57ee144b471022bccca5f06ef68134ccc17208)
+++ uspace/lib/libc/include/ipc/loader.h	(revision 47e0a05baa886b025c008b7e51748be0a29cd784)
@@ -40,4 +40,5 @@
 typedef enum {
 	LOADER_HELLO = IPC_FIRST_USER_METHOD,
+	LOADER_GET_TASKID,
 	LOADER_SET_PATHNAME,
 	LOADER_SET_ARGS,
Index: uspace/srv/loader/main.c
===================================================================
--- uspace/srv/loader/main.c	(revision 2c57ee144b471022bccca5f06ef68134ccc17208)
+++ uspace/srv/loader/main.c	(revision 47e0a05baa886b025c008b7e51748be0a29cd784)
@@ -78,4 +78,25 @@
 static char *arg_buf = NULL;
 
+static int loader_get_taskid(ipc_callid_t rid, ipc_call_t *request)
+{
+	ipc_callid_t callid;
+	task_id_t task_id;
+	size_t len;
+
+	task_id = task_get_id();
+
+	if (!ipc_data_read_receive(&callid, &len)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+
+	if (len > sizeof(task_id)) len = sizeof(task_id);
+
+	ipc_data_write_finalize(callid, &task_id, len);
+	ipc_answer_0(rid, EOK);
+}
+
+
 /** Receive a call setting pathname of the program to execute.
  *
@@ -275,4 +296,7 @@
 //			call.in_phone_hash, IPC_GET_METHOD(call));
 		switch (IPC_GET_METHOD(call)) {
+		case LOADER_GET_TASKID:
+			loader_get_taskid(callid, &call);
+			continue;
 		case LOADER_SET_PATHNAME:
 			loader_set_pathname(callid, &call);
