0

I´m trying to get some values displayed on an eInk-Display (via SPI). I already wrote the software to initialize the display and display the values passed as command-line arguments. The problem is, because of the eInk-technology it takes a few seconds for the display to have fully actualized, so the display-program is also running for this time.

The other ("Master"-) program collects the values and does other stuff. It has a main loop, which has to be cycled through at least 10x/second. So I want to start the displaying program from within the main loop and immediately continue with the loop.

When using system() or execl(), the Master-program either waits till the display program is finished or exits into the new process.

Is there a way to just start other programs out of other ones without any further connection between them? It should run on Linux. May fork() be a solution?

4
  • You can try system("your command") or pthreads. Commented Mar 5, 2018 at 13:12
  • fork() + exec() is one way. system("your command &"); is another. Commented Mar 5, 2018 at 13:14
  • 1
    Do you care if the program failed to start? Commented Mar 5, 2018 at 13:17
  • "t has a main loop, which has to be cycled through at least 10x/second" What kind of real-time requirement is that? If your main loop takes longer than 100ms to execute, you have some real serious problems. Now what you should be doing here, is to write a multi-threaded program. Commented Mar 5, 2018 at 13:57

1 Answer 1

2

quick and dirty way: use system with a background suffix (&)

char cmd[200];
sprintf("%190s &","your_command");
system(cmd);

note that it's not portable because it depends on the underlying shell. For windows you would do:

sprintf("start %190s","your_command");

The main drawback of the quick & dirty solution is that it's "fire & forget". If the program fails to execute properly, you'll still have a 0 return code as long as the shell could launch the process.

A portable method (also allowing to take care of the return code of the process) is slightly more complex, involving running a system call from a thread or a forked executable. The quick & dirty solution does a fork + exec of a shell command behind the scenes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.