Next: execl() Up: Process Control and Management Previous: Process Control and Management

Running UNIX Commands from C

We can run commands from a C program just as if they were from the UNIX command line by using the system() function. NOTE: this can save us a lot of time and hassle as we can run other (proven) programs, scripts etc. to do set tasks.

int system(char *string) - where string can be the name of a unix utility, an executable shell script or a user program. System returns the exit status of the shell.

Example: Call ls from a program

system is a call that is made up of 3 other commands: execl(), wait() and fork()
Fri May 20 13:40:49 BST 1994