Index: uspace/app/bdsh/exec.c
===================================================================
--- uspace/app/bdsh/exec.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/app/bdsh/exec.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -114,4 +114,5 @@
 	task_id_t tid;
 	char *tmp;
+	int retval;
 
 	tmp = str_dup(find_command(cmd));
@@ -126,5 +127,8 @@
 	}
 	
-	task_wait(tid);
+	task_wait(tid, &retval);
+	if (retval != 0)
+		printf("Command failed (return value %d).\n", retval);
+
 	return 0;
 }
Index: uspace/app/getvc/getvc.c
===================================================================
--- uspace/app/getvc/getvc.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/app/getvc/getvc.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -74,4 +74,6 @@
 int main(int argc, char *argv[])
 {
+	int retval;
+
 	if (argc < 3) {
 		usage();
@@ -98,5 +100,5 @@
 	version_print(argv[1]);
 	task_id_t id = spawn(argv[2]);
-	task_wait(id);
+	task_wait(id, &retval);
 	
 	return 0;
Index: uspace/lib/libc/generic/libc.c
===================================================================
--- uspace/lib/libc/generic/libc.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/lib/libc/generic/libc.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -62,4 +62,6 @@
 void __main(void *pcb_ptr)
 {
+	int retval;
+
 	__heap_init();
 	__async_init();
@@ -83,6 +85,8 @@
 	}
 	
-	main(argc, argv);
+	retval = main(argc, argv);
+
 	__stdio_done();
+	(void) task_retval(retval);
 }
 
Index: uspace/lib/libc/generic/task.c
===================================================================
--- uspace/lib/libc/generic/task.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/lib/libc/generic/task.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -149,7 +149,23 @@
 }
 
-int task_wait(task_id_t id)
+int task_wait(task_id_t id, int *retval)
 {
-	return (int) async_req_2_0(PHONE_NS, NS_TASK_WAIT, LOWER32(id), UPPER32(id));
+	ipcarg_t rv;
+	int rc;
+
+	rc = (int) async_req_2_1(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
+	    UPPER32(id), &rv);
+	*retval = rv;
+
+	return rc;
+}
+
+int task_retval(int val)
+{
+	task_id_t id;
+
+	id = task_get_id();
+	return (int) async_req_3_0(PHONE_NS, NS_RETVAL, LOWER32(id),
+	    UPPER32(id), val);
 }
 
Index: uspace/lib/libc/include/ipc/ns.h
===================================================================
--- uspace/lib/libc/include/ipc/ns.h	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/lib/libc/include/ipc/ns.h	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -40,5 +40,6 @@
 typedef enum {
 	NS_PING = IPC_FIRST_USER_METHOD,
-	NS_TASK_WAIT
+	NS_TASK_WAIT,
+	NS_RETVAL
 } ns_request_t;
 
Index: uspace/lib/libc/include/task.h
===================================================================
--- uspace/lib/libc/include/task.h	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/lib/libc/include/task.h	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -43,5 +43,7 @@
 extern int task_set_name(const char *name);
 extern task_id_t task_spawn(const char *path, char *const argv[]);
-extern int task_wait(task_id_t id);
+extern int task_wait(task_id_t id, int *retval);
+extern int task_retval(int val);
+
 
 #endif
Index: uspace/srv/ns/ns.c
===================================================================
--- uspace/srv/ns/ns.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/srv/ns/ns.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -171,4 +171,7 @@
 			wait_for_task(id, &call, callid);
 			continue;
+		case NS_RETVAL:
+			retval = ns_task_retval(&call);
+			break;
 		default:
 			retval = ENOENT;
Index: uspace/srv/ns/task.c
===================================================================
--- uspace/srv/ns/task.c	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/srv/ns/task.c	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -64,4 +64,5 @@
 	link_t link;
 	task_id_t id;    /**< Task ID. */
+	int retval;
 	bool destroyed;
 } hashed_task_t;
@@ -174,5 +175,5 @@
 		
 		if (!(pr->callid & IPC_CALLID_NOTIFICATION))
-			ipc_answer_0(pr->callid, EOK);
+			ipc_answer_1(pr->callid, EOK, ht->retval);
 		
 		hash_table_remove(&task_hash_table, keys, 2);
@@ -222,4 +223,5 @@
 		ht->id = id;
 		ht->destroyed = (et == TASK_CREATE) ? false : true;
+		ht->retval = -1;
 		hash_table_insert(&task_hash_table, keys, &ht->link);
 	} else {
@@ -262,5 +264,27 @@
 out:
 	if (!(callid & IPC_CALLID_NOTIFICATION))
-		ipc_answer_0(callid, retval);
+		ipc_answer_1(callid, retval, ht->retval);
+}
+
+int ns_task_retval(ipc_call_t *call)
+{
+	task_id_t id;
+	unsigned long keys[2];
+
+	id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
+
+	keys[0] = LOWER32(id);
+	keys[1] = UPPER32(id);
+	
+	link_t *link = hash_table_find(&task_hash_table, keys);
+	hashed_task_t *ht = (link != NULL) ?
+	    hash_table_get_instance(link, hashed_task_t, link) : NULL;
+	
+	if ((ht == NULL) || ht->destroyed)
+		return EINVAL;
+
+	ht->retval = IPC_GET_ARG3(*call);
+
+	return EOK;
 }
 
Index: uspace/srv/ns/task.h
===================================================================
--- uspace/srv/ns/task.h	(revision d68e4d573ccb8f5b2c980725f2f3c84831e0c8b5)
+++ uspace/srv/ns/task.h	(revision 7114d836ff84c10f98376e50246b4d5e34146131)
@@ -43,4 +43,6 @@
 extern void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid);
 
+extern int ns_task_retval(ipc_call_t *call);
+
 #endif
 
