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 9009345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:10:00+00:00 2026-06-16T02:10:00+00:00

I am creating three child processes in C using the following: typedef struct{ STARTUPINFO

  • 0

I am creating three child processes in C using the following:

    typedef struct{
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
    }PROCESS_PARAMS;

    PROCESS_PARAMS pChildren[3];

    wchar_t *szCmdline[3] = {L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child1/tclient\"",
 L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child2/tclient\"", 
L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child3/tclient\""};


    for (i=0; i<3; i++)
                {
                    pChildren[i].si.cb = sizeof(pChildren[i].si);
                    GetStartupInfo(&pChildren[i].si);
                    ZeroMemory(&pChildren[i].pi, sizeof(pChildren[i].pi));

                    // Start the child processes.
                    CreateProcess(NULL,   // No module name (use command line)
                                  szCmdline[i],          // Command line
                                  NULL,           // Process handle not inheritable
                                  NULL,           // Thread handle not inheritable
                                  FALSE,          // Set handle inheritance to FALSE
                                  0,              // No creation flags
                                  NULL,           // Use parent's environment block
                                  NULL,           // Use parent's starting directory
                                  &pChildren[i].si,            // Pointer to STARTUPINFO structure
                                  &pChildren[i].pi);         // Pointer to PROCESS_INFORMATION structure
                }

But the code crashes while creating the new processes and i suspect something is wrong with the command line arguments.
But I am not sure what is wrong. Could someone please help me with this?
Thanks.

PS: it works when for one instance when i give it in the following way:

wchar_t szCmdline[] = L"nmctest -s \"TwonkyServer[julka]\" -r \"NMC Test DMR [julka960]\" -tLDMR -d \" /child1/twonkyclient\""; 

And then in i do:

CreateProcess(NULL,   // No module name (use command line)
                                  szCmdline,          // Command line
                                  NULL,           // Process handle not inheritable
                                  NULL,           // Thread handle not inheritable
                                  FALSE,          // Set handle inheritance to FALSE
                                  0,              // No creation flags
                                  NULL,           // Use parent's environment block
                                  NULL,           // Use parent's starting directory
                                  &pChildren[i].si,            // Pointer to STARTUPINFO structure
                                  &pChildren[i].pi); 

Note that i give szCmdline instead of szCmdline[i]. THen it works but i am not sure when is the problem in the topmost code.

  • 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-16T02:10:01+00:00Added an answer on June 16, 2026 at 2:10 am

    From the docs for CreateProcess():

    The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, thefunction may cause an access violation.

    And it appears that you’re using the Unicode version and passing in pointers to string literals (which are not modifiable).

    This isn’t a problem for the CreateProcessA() version of the function because internally it converts the ANSI command line to Unicode, and the converted string ends up in modifiable memory.

    In the version that works you’re initializing the string into an array that’s modifiable and passing the address of that array instead of passing a pointer to a string literal.

    For some history on this situation, see Raymond Chen’s “Why does the CreateProcess function modify its input command line?”.

    Example code if you need a bit more help:

    // a helper function to duplicate a unicode string
    wchar_t* xwcsdup( wchar_t const* s)
    {
        wchar_t* p = _wcsdup(s);
    
        if (!p) {
            abort();    // or however you want to fail miserably
        }
    
        return p;
    }
    
    
    
    // and your loop to create the processes...
    
    for (i=0; i<3; i++)
    {
        wchar_t* cmdline = xwcsdup(szCmdline[i]);
    
        pChildren[i].si.cb = sizeof(pChildren[i].si);
        GetStartupInfo(&pChildren[i].si);
        ZeroMemory(&pChildren[i].pi, sizeof(pChildren[i].pi));
    
        // Start the child processes.
        CreateProcess(NULL,   // No module name (use command line)
                      cmdline,        // Command line
                      NULL,           // Process handle not inheritable
                      NULL,           // Thread handle not inheritable
                      FALSE,          // Set handle inheritance to FALSE
                      0,              // No creation flags
                      NULL,           // Use parent's environment block
                      NULL,           // Use parent's starting directory
                      &pChildren[i].si,            // Pointer to STARTUPINFO structure
                      &pChildren[i].pi);         // Pointer to PROCESS_INFORMATION structure
    
        free(cmdline);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code sends messages from child processes to their parents using socket pairs.
I have three entities: Country, State and City with the following relationships: When creating
I'm creating child processes with CreateProcess function in MSVC++ 2010, and before that setting
I'm creating new processes using System.Diagnostics.Process class from my application. I want this processes
My current program is creating child processes and giving them work (CPU intensive work).
In my application I am creating a bunch of child processes. After fork() I
I am creating solution and inside I have three projects: A WCF Service Library
I am creating an app that has three tabs on the main screen. Each
I am having issues creating a simple 2D scene with Three.js. I would like
I am creating window c# desktop application I have three columns in my datagridview

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.