In an operating system, the user can write so many codes and made them executable and then run each of them as background processes to achieve multi-tasking. The another easy method to achieve the multitasking is using a Shell script in which all the commands to execute the codes as background process are scripted into, but it is not a proper method since the user can have little control over the processes which are initiated by the Shell script. The same thing can be done by executing a single C code in which the system () function opens up a new Shell and pass the commands to them. Since it may open up a new Shell for executing each and every process the better method is to use execve () function in the code which itself can execute a new process.
In this project the Raspberrypi board is loaded with Ubuntu and is remotely accessed using VNC. The Raspberrypi board is also connected to the internet. There are 26 connectors which can be taken out from the connector port of the Raspberrypi board. All the connector pins are taken out using 13*2 pin female connectors and at the other end of their wire 26 pin Burg stick male connectors are attached. The Burg stick male connectors allow each pin out from the Raspberrypi board to be plugged into the holes of a breadboard. To access the pins that coming out of the Broadcom controller of the Raspberrypi board using C language, a C library is available called “bcm2835” which has been downloaded and installed.
There are eight general purpose IO pins on the 13*2 pin connectors of the Raspberrypi board and to each one of them a LED is connected through 1K resistor. Separate code has been written to blink the LEDs individually and made them into executable files named blink2, blink3, blink4, blink5, blink6, blink7 and blink8. It is suggested to keep all the .c files and the executable files in a single folder for this particular project.
The user can run any of the LED blinking programs from the command line. For example to execute the file ‘blink1’, the user can use the following command:
The user can perform multi-tasking on them by entering the following commands one after the other. The user can perform multi-tasking with the eight LED codes by entering the following eight commands one after the other.
The following section discusses how to execute any of the above executable files from another C code rather than using the command line to pass the commands for execution.
It is declared in the header file <unistd.h>. The prototype of the function is given as follows;
int execve(const char *filename, char *const argv, char *const envp);
The first parameter is the name of the file to be executed; the second parameter is the number of arguments that need to be passed to the file to be executed and the third parameter is the arguments. All the three parameters need be passed in the form of string.
To execute the file “blink1” using the execve () function the user can use the following statement in a C code.
execve ( “blink1”, 0, 0 );
The file blink1 is not taking any arguments and hence the second and third parameters are left as 0.
For execute the LED blinking codes as from another C code, simply open up a new .c file in vim editor and write down the following simple code;
int main ()
execve ( “./blink1”, 0, 0 );
int main ()
execve ( “./blink2”, 0, 0 );
int main ()
execve ( “./blink8”, 0, 0 );
Save this file with a name, say “execve_blink.c” and then compile them into an executable file “execve_blink”.
To execute the code use the following command:
*** Make sure that all the executable files blink1, blink2 etc. are there in the same folder with the executable file “execve_blink_all”.
***Note that in this project the latest version of library “bcm2835” is used with an old version of Raspberrypi board. It is not possible to access the pin number 13 of the old board with the latest library version and hence in the code “blink3.c” the pin number 24 is used to blink the 3rd LED. The circuit diagram is also drawn accordingly. Those who have the latest version of the board can use the pin 13 without any trouble.
To find the ‘Revision’ and other important details about the Raspberrypi board, use the following command: