Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:33:07+00:00 2026-05-27T10:33:07+00:00

In my program, I need to call a subprocess *sub_prog*. I do this with

  • 0

In my program, I need to call a subprocess *sub_prog*. I do this with a system call, e.g. system("sub_prog arg1 arg2...");. Simple enough; all works correctly.

Unfortunately the supercomputer I am using does not support the spawning of subprocess (due to the architecture, you can’t use fork(), popen() etc. with MPI. It’s just a fact.). So the solution would be to make *sub_prog* a (shared) library and call it as a library function, rather than as a sub-process.

I created the shared library *libsub_prog.so* fine. The problem is – the function I want to call is *sub_prog* itself, i.e., I want to call main(argc,argv) of sub_prog.

Questions regarding shared libraries usually center around calling member functions from shared libraries. But what if I want to call the main function itself?

(I thought about renaming *sub_prog*’s int main to another name, essentially turning its main into just another member function. But there are several global variables deefined right before int main). Would I have to put these in a header globals.h and go in and manually insert “#include globals.h” in every source file?)

Thanks to all in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:33:07+00:00Added an answer on May 27, 2026 at 10:33 am

    I would just turn it into a normal function by giving it a different name, and call it from the main executable using this new name. If you declare the function to have extern "C" linkage, it should be easy to locate the function at runtime using dlsym. As to the global variables, you shouldn’t need to do anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my C++ program, I need to call this c API: GConn* gnet_conn_new (const
I want to call a process via a python program, however, this process need
I need to call from my code for some other program . And I
I need to call some methods in Wininet.dll from a Java program. I can
For RMI on server-side, do we need to start rmiregistry program, or just call
I need to interface a C console program (as subprocess) with Python using stdin/stdout.
I need to call some DOS interrupts (Services) from a C/C++ program, I tried
I need to call a C++ member function from a C program. I created
I need to call a function from another program. If the other program were
I am writing a program in C++ where I need to call a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.