Is there any alternate for fork() api in vxworks? - VxWorks

This is a discussion on Is there any alternate for fork() api in vxworks? - VxWorks ; Hi there, i am compiling a snip of code in VxWorks which was actually written for Linux. It gives me a warning "undeclared function" for fork(). Please tell me so that i can fork a process in VxWorks. How can ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Is there any alternate for fork() api in vxworks?

  1. Is there any alternate for fork() api in vxworks?

    Hi there,
    i am compiling a snip of code in VxWorks which was actually written
    for Linux. It gives me a warning "undeclared function" for fork().
    Please tell me so that i can fork a process in VxWorks.
    How can Linux Kernel routines like fork, exec, getpid, usleep etc can
    be used in VxWorks?

  2. Re: Is there any alternate for fork() api in vxworks?

    On 4 Dic, 06:16, ais...@gmail.com wrote:
    > Hi there,
    > i am compiling a snip of code in VxWorks which was actually written
    > for Linux. It gives me a warning "undeclared function" for fork().
    > Please tell me so that i can fork a process in VxWorks.
    > How can Linux Kernel routines like fork, exec, getpid, usleep etc can
    > be used in VxWorks?


    They cannot This is one of the major issues in porting code from
    Unix to VxWorks. In fact, VxWorks doesn't have the concept of process,
    but it works on a task basis, so there is just no fork routine for it,
    neither you can write a "dummy" for it. The best thing you can do is
    to read WindRiver's vxworks programmer's guide, and you will have a
    clear idea of it.

    The only think you can do is to refactor the code in such the way that
    fork must not be used. Depending on the complexity of the code, this
    can be quite a challenging job.

    And yes, you are not the first one facing this problem...

    Ciao

  3. Re: Is there any alternate for fork() api in vxworks?

    hi,
    thanks for your reply.
    Can we not use pthread_create or taskSpawn to implement fork?
    assume this psuedo code:

    int pid = fork();
    if(pid) /*parent*/
    {
    blah blah blah....
    }
    else /*child*/
    {
    blah blah blah...
    }

    Now as per the work performed by the parent and child, can we not
    create two functions (say parent(), child() ) by using taskSpawn() or
    pthread_create and do it like this--

    taskSpawn(parent())
    {
    /*same as done by if statement above*/
    }
    taskSpawn(child)
    {
    /*same as done by else above*/
    }


    benelli.giacomo@gmail.com wrote:
    > On 4 Dic, 06:16, ais...@gmail.com wrote:
    > > Hi there,
    > > i am compiling a snip of code in VxWorks which was actually written
    > > for Linux. It gives me a warning "undeclared function" for fork().
    > > Please tell me so that i can fork a process in VxWorks.
    > > How can Linux Kernel routines like fork, exec, getpid, usleep etc can
    > > be used in VxWorks?

    >
    > They cannot This is one of the major issues in porting code from
    > Unix to VxWorks. In fact, VxWorks doesn't have the concept of process,
    > but it works on a task basis, so there is just no fork routine for it,
    > neither you can write a "dummy" for it. The best thing you can do is
    > to read WindRiver's vxworks programmer's guide, and you will have a
    > clear idea of it.
    >
    > The only think you can do is to refactor the code in such the way that
    > fork must not be used. Depending on the complexity of the code, this
    > can be quite a challenging job.
    >
    > And yes, you are not the first one facing this problem...
    >
    > Ciao


  4. Re: Is there any alternate for fork() api in vxworks?

    On 4 Dic, 11:18, ais...@gmail.com wrote:
    > hi,
    > thanks for your reply.
    > Can we not use pthread_create or taskSpawn to implement fork?
    > assume this psuedo code:
    >
    > int pid = fork();
    > if(pid) /*parent*/
    > {
    > blah blah blah....}
    >
    > else /*child*/
    > {
    > blah blah blah...
    >
    > }
    >
    > Now as per the work performed by the parent and child, can we not
    > create two functions (say parent(), child() ) by using taskSpawn() or
    > pthread_create and do it like this--
    >
    > taskSpawn(parent())
    > {
    > /*same as done by if statement above*/}
    >
    > taskSpawn(child)
    > {
    > /*same as done by else above*/}
    > benelli.giac...@gmail.com wrote:
    > > On 4 Dic, 06:16, ais...@gmail.com wrote:
    > > > Hi there,
    > > > i am compiling a snip of code in VxWorks which was actually written
    > > > for Linux. It gives me a warning "undeclared function" for fork().
    > > > Please tell me so that i can fork a process in VxWorks.
    > > > How can Linux Kernel routines like fork, exec, getpid, usleep etc can
    > > > be used in VxWorks?

    >
    > > They cannot This is one of the major issues in porting code from
    > > Unix to VxWorks. In fact, VxWorks doesn't have the concept of process,
    > > but it works on a task basis, so there is just no fork routine for it,
    > > neither you can write a "dummy" for it. The best thing you can do is
    > > to read WindRiver's vxworks programmer's guide, and you will have a
    > > clear idea of it.

    >
    > > The only think you can do is to refactor the code in such the way that
    > > fork must not be used. Depending on the complexity of the code, this
    > > can be quite a challenging job.

    >
    > > And yes, you are not the first one facing this problem...

    >
    > > Ciao


    It depends on what you want to do... If you spawn a task, either using
    pthread or vxworks' routines, this task isn't in a relationship father-
    child with its caller and it isn't a copy of its caller ( since this,
    the absence of "exec"). So, for example, if you intend to use fork to
    make a server handle multiple connections, you have to take this into
    account and design your code accordingly.

    A vxworks task is basically just a function that executes in its own
    context, concurrently with any other task.

  5. Re: Is there any alternate for fork() api in vxworks?

    On Dec 3, 9:16 pm, ais...@gmail.com wrote:
    > Hi there,
    > i am compiling a snip of code in VxWorks which was actually written
    > for Linux. It gives me a warning "undeclared function" for fork().
    > Please tell me so that i can fork a process in VxWorks.
    > How can Linux Kernel routines like fork, exec, getpid, usleep etc can
    > be used in VxWorks?


    What version of VxWorks are you using? Prior to the version 6 VxWorks
    did not support the concept of process. Starting with VxWorks 6.0 it
    does (they are called Real Time Process, or RTP). This said the
    process concept in VxWorks 6 is analogous but not identical to the
    process concept in Unix. In particular the execution environment is
    not meant to be a full-blown multi-user system (ala POSIX IEEE Std
    1003.13's PSE54 profile). Although VxWorks 6.4's execution environment
    for processes is certified for the PSE52 profile, the available POSIX
    APIs for RTPs on VxWorks make it fall roughly between the PSE52 and
    PSE53 profiles. For instance: the fork() and exec() API are part of
    the PSE53 profile and are not available on VxWorks. The getpid() API
    is also part of the PSE53 profile but is available on VxWorks (again,
    in the process execution environment, not the kernel).

    There are often, but not always, API that you can use to emulate or
    replace the POSIX API that are not supported. For instance you could
    use rtpSpawn() instead of the fork()/exec() couple. The goal is the
    same, i.e. launching another process, but the details are different
    (rtpSpawn() can be seen as a simplified posix_spawn()) so it may
    require some work to adapt your Unix code. Another example is
    usleep(), which is not supported, but that you could replace with
    nanosleep().

    Hope this helps,

    --
    PAD


+ Reply to Thread