Posts: 144
Joined: Tue Jan 24, 2012 5:53 pm
Contact: Website

Running programs in harness

Sat Mar 17, 2018 9:25 pm

Pretty sure this will work OK because it must be a very commonplace scenario, but just realising that I don't properly understand what's happening in the background:

I want to run two programs in harness (all on the same Pi). So one program will read multiplexed sensor data from a USB port frequently eg every 2 seconds, parse and process it and then make the data available in a standard eg JSON format to any requesting program eg via an IP port. The second program (which will actually be a standalone third-party program) understands the standard data format, will make appropriate IP data requests and can then perform a lot of further processing on the data.

Presumably I can just assume that this 2-program configuration should work just fine (providing of course that the overall workload doesn't get too intensive), after all my first program is effectively just acting as a driver?

But the second part of my question was whether this is all likely to happen on a single core? Will a second core kick in automatically, eg to handle a separate thread for the second program? Do I have any control over this? More curiosity than anything.

Posts: 10629
Joined: Tue Jul 17, 2012 3:02 pm

Re: Running programs in harness

Sun Mar 18, 2018 7:34 am

I presume you are running Raspbian on you Pi.

Raspbian is a version of Debian which is a Linux distribution.

Linux is a remake of Unix.

Unix can run many programs at the same time. It's a multi-user, multi-tasking system. Even if you only have a single core!

If you open up a command line terminal window and type:

$ ps -A

You will see a list of all the many programs (processes) that are running on your Pi.

You can start one of your programs and have it run in the background with

$ ./myProgA &

Then you can start another program to run at the same time:

$ ./myProgB

Or open two terminal windows and run one program in each.

Of course you are likely to want to run your programs automatically from startup. We can tackle that issue when you have them working.

Your programs will run on whatever cores the Linux kernel chooses as it tries to run things optimally. Or you can select the cores a program runs on my using the "taskset" command. Normally one does need to bother with that.

Posts: 7825
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Running programs in harness

Sun Mar 18, 2018 8:23 am

Linux will shuffle threads and processes around as it sees fit on multicore systems. You can bind both threads and processes to a certain core if you want to, though.

• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere

Return to “General programming discussion”