VxWorks stdout from tasks

Posted on 2007-08-01
Last Modified: 2013-12-26

I'm hoping there's a couple experts out there with some VxWorks experience.

I'm unable to get printf - stdout to my shell from tasks that I've spawned.  From what I could gather this is because the shell runs at a much higher priority than my task.  I think there's a way to get a task's stdout to a serial port, however this isn't a great solution for me since the target is in another building.

I'd still like to get printf output from tasks just for development and debugging puposes.  Is there some other way to do that like redirecting a task's stdout or telnet to a machine connected to the serial output.....?

Question by:JohnSantaFe
    LVL 86

    Assisted Solution

    Can you redirect stdout to a file and read that using 'tail -f'? I.e.

    mytask 1>&2 mytasklog

    tail -f mytasklog
    LVL 6

    Accepted Solution

    Something is a bit strange with what you were told. Shell's don't typically run, much less at a higher priority, when a process id running under it. It has been a while since I used VxWorks, but I never had a problem getting printf() output.

    You named the most common workarounds. Is there a nearby machine you can access the serial port on? You can also use a fprintf()/flush() to get your info out to a file/serial port, etc...

    Is the process daemonized or running in the background (started with &)?

    Is your shell a real shell or is it Wind River's cut down shell?


    Author Comment

    Well, let me post some sample code to show the problem I'm having with printf.  I'm using the generic Tornado shell.

    #include "cstdio"

    void myTask(void);

    int myData = 0;
    int tidMyTask = 0;

    int start(void)
       printf("myData before task is:  %i\n", myData);

       tidMyTask = taskSpawn ("tTaskName", 100, 0, 20000,
                                   (FUNCPTR)myTask, 0,0,0,0,0,0,0,0,0,0);


      printf("myData after task is: %i\n", myData);


     return 1;

    void myTask(void)
      printf("Starting my task");   //this never happens

      myData = 56;   //this does happen

      printf("myData inside of task is: %i\n", myData);  //this never happens

    Output from the Tornado shell

    myData before task is: 0
    myData after task is: 56
    value = 1 = 0x1

    LVL 6

    Expert Comment

    Try checking the return from printf(). If it is -1, check errno. There might be a clue there.

    My first thought is you don't have a stdout assigned. The only failures are from your spawn'd task. That implies that stdio assigns are not happening. Without the source to tornado, you won't know for sure, but if you treat it like there is no default terminal assigned, you will be better off. Try using a file.

    Are you NFS mounted?


    Assisted Solution

    I understood the problem here.As per the VxWorks, the root task is having the priority of 100.That means int start(void) which is the root task is having the prority 100.But you are spawning one more task inside the root task which is of the same priority.So what will happen is your void myTask(void)
    task will be executed once the execution of int start(void) is OVER.But before the root task is over, you are deleting the task by the statement  taskDelete(tidMyTask);

    So what you have to try out here is, spawn the task with the prority 99 which is a higher priority than the root task.

    tidMyTask = taskSpawn ("tTaskName", 99, 0, 20000,
                                   (FUNCPTR)myTask, 0,0,0,0,0,0,0,0,0,0);

    Otherwise, spawn the task with priority 100 only, but remove the statement


    Author Comment


    Thanks.  Unfortunately it's not a problem with the task running.  I'm sure the task runs because the value of myData changes.

    I've moved on to Windriver's Workbench and the newer version of Vxworks so I've abandoned the issue.

    Thanks for the replies.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now