Executing a child process in "C"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Executing a child process in "C"

  1. #1
    Join Date
    Oct 2012
    Location
    New Zealand
    Posts
    11

    Executing a child process in "C"

    Anyone know how I can run this as a separate process from the parent program, like a child process,

    and return the result back to the parent program.

    this script is as follows.

    if file "/Stuff/s" exists then continue to run, if file "/Stuff/t" exists, then print "started" if file "/Stuff/t" does not exists, then print "stopped"

    if file "/Stuff/s" does not exist then print "quit" and then quit.


    Code:
    void controlxmmscheck( ) {
    
    if( access( "/Stuff/s", F_OK ) != -1 ) {
    
    xmmscheck
    
    } else {
    
    gtk_label_set_text(GTK_LABEL (label_status), gettext("quit"));
    
    }
    
    void controldiversion( ) {
    
    if( access( "/Stuff/s", F_OK ) != -1 ) {
    
    diversion
    
    } else {
    
    gtk_label_set_text(GTK_LABEL (label_status), gettext("quit"));
    
    }
    
    void xmmscheck( ) {
    
    
    /* Check if /stream1/t exists */
    if( access( "/Stuff/t", F_OK ) != -1 ) {
    
    /* Then status is "started" */
    
    gtk_label_set_text(GTK_LABEL (label_status), gettext("started"));
    
    /* Switch to diversion function */
    controldiversion
    
    /* Or else wait for 5 seconds */
    } else {
    sleep(5);
    
    /* Start this File all over again */
    controlxmmscheck
    
    }
    
    
    void diversion( ) {
    
    /* check if file /stream1/t exists */
    if( access( "/Stuff/t", F_OK ) != -1 ) {
    
    */ Then wait for 5 Seconds */
    sleep(5);
    
    /* Start this function again */
    controldiversion
    
    } else {
    
    
    /* then status is stopped */
    gtk_label_set_text(GTK_LABEL (label_status), gettext("stopped"));
    
    /* Switch to xmmscheck function */
    controlxmmscheck
    
    
    }

  2. #2
    Join Date
    Oct 2012
    Location
    New Zealand
    Posts
    11

    Re: Executing a child process in "C"

    I have made the same script in bash,

    If iwas to execute this script as a child process I would do something like

    Code:
    bash -c 'script &'
    I wish to achieve a similar this in "C"

    I know this may be simple for the experts, I have self taught myself by looking a source codes and figuring stuff out.


    if file "/Stuff/s" exists then continue to run, if file "/Stuff/t" exists, then "mkdir /Stuff/test" if file "/Stuff/t" does not exists, then "rmdir /Stuff/test"

    if file "/Stuff/s" does not exist then print or echo "quit" and then quit.



    Code:
    #! /bin/bash
    
    
    function controlxmmscheck {
    
    if [ -s /Stuff/s ]; then
    
    xmmscheck
    
    else
    
    echo "quit controlxmmscheck"
    
    fi
    }
    
    function controldiversion {
    
    if [ -s /Stuff/s ]; then
    
    diversion
    
    else
    rm /Stuff/t
    echo "quit controldiversion"
    
    fi
    }
    
    function xmmscheck {
    
    # xmmscheck1
    # Check if /stream1/t exists
    if [ -s /Stuff/t ]; then
    
    mkdir /Stuff/test
    
    # Switch to diversion function
    controldiversion
    
    # Or else wait for 5 seconds
    else
    sleep 5
    
    # Start this File all over again
    controlxmmscheck
    fi
    }
    
    
    
    
    function diversion {
    # diversion
    # check if file /stream1/t exists
    if [ -s /Stuff/t ]; then
    
    # Then wait for 5 Seconds
    sleep 5
    
    # Start this function again
    controldiversion
    
    else
    rmdir /Stuff/test
    
    # Switch to xmmscheck function
    controlxmmscheck
    fi
    
    }
    
    controlxmmscheck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center