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

  • Home
  • SEARCH
  • 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 8045605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:36:00+00:00 2026-06-05T05:36:00+00:00

I am working on Linux with code that makes a system() call to run

  • 0

I am working on Linux with code that makes a system() call to run a python program. I am interested in the value returned by this function call to understand how the python program execution went.

So far, I have found 3 results:

  • When the python process completes successfully, value returned by system() is 0

  • When the python process is killed mid-execution (using kill -9 pid), value returned by system() is 9

  • When the python process fails on its own due to incorrect parameters, value returned by system() is 512

This does not fit with what I’ve read about system() function.

Furthermore, the code for the python program being invoked shows that it exits with sys.exit(2) when any error is encountered, and sys.exit(0) when execution completes successfully.

Could anyone relate these two? Am I interpreting the return value in a wrong manner? Is there some Linux processing involved that takes the argument of the sys.exit() function of the python program and returns value of system() based on it?

  • 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-06-05T05:36:02+00:00Added an answer on June 5, 2026 at 5:36 am

    The exit code of the program you call can be fetched with WEXITSTATUS(status) as per the manual page. Also see the manual page for wait.

    int status = system("/path/to/my/program");
    if (status < 0)
        std::cout << "Error: " << strerror(errno) << '\n';
    else
    {
        if (WIFEXITED(status))
            std::cout << "Program returned normally, exit code " << WEXITSTATUS(status) << '\n';
        else
            std::cout << "Program exited abnormaly\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new in programming under linux and trying to get working this code:
I am working with code base that supports both Linux and Windows platform. Now,
I am working in Linux, Eclipse CDT, g++, with Boost library. Having existing program
The scenario I have access to this old linux server, that no longer receives
I am currently working with a piece of code that has been written by
I am working on an embedded system running Linux on a DSP. Now we
I'm working on a large collaborative C++ project that is both developed and run
I am working on a program that uses mpi (openmpi 1.4.3) and pthreads, working
First off i'm new to Linux programming so apologies if this makes no sense
In a team environment on a Linux system I just pulled the latest code

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.