The thread ID of thread running new app main() function is returned.

Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
---
 core/app.cc        | 12 ++++++++++--
 include/osv/app.hh |  7 ++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/core/app.cc b/core/app.cc
index ad3145f..6ea5d6e 100644
--- a/core/app.cc
+++ b/core/app.cc
@@ -133,8 +133,12 @@ shared_app_t application::run(const std::string& command,
     return app;
 }
 
-void run(const std::vector<std::string>& args) {
-    application::run(args);
+void run(const std::vector<std::string>& args, pid_t *pid) {
+    auto app = application::run(args);
+    if (pid) {
+        *pid = app->get_main_thread_id();
+        assert((*pid) != 0);
+    }
 }
 
 shared_app_t application::run_and_join(const std::string& command,
@@ -419,6 +423,10 @@ std::string application::get_command()
     return _command;
 }
 
+pid_t application::get_main_thread_id() {
+    return pthread_gettid_np(_thread);
+}
+
 // For simplicity, we will not reuse bits in the bitmap, since no destructor is
 // assigned to the program. In that case, a simple counter would do. But coding
 // this way is easy, and make this future extension simple.
diff --git a/include/osv/app.hh b/include/osv/app.hh
index 6fa503a..90bc7ce 100644
--- a/include/osv/app.hh
+++ b/include/osv/app.hh
@@ -176,6 +176,11 @@ public:
      */
     std::string get_command();
 
+    /**
+      * Returns thread_id/PID of thread running app main() function.
+      */
+    pid_t get_main_thread_id();
+
     std::shared_ptr<application_runtime> runtime() const { return _runtime; }
     std::shared_ptr<elf::object> lib() const { return _lib; }
 
@@ -238,7 +243,7 @@ namespace osv {
  * Creates a new app
  * args Arguments passed to the program's main() function.
  */
-void run(const std::vector<std::string>& args);
+void run(const std::vector<std::string>& args, pid_t *pid=nullptr);
 
 namespace this_application {
 
-- 
2.9.3

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to