Download ${Unix_Tools} - The Computer Laboratory
Transcript
Unix inter-process communication mechanisms
invocation
return value
command line arguments
sockets
environment variables
current directory
shared memory
files and pipes
Process
standard input/output/error
semaphores
signals
messages
resource limits, umask
priority
execution time
not supported by shell
supported by shell
13
Command-line arguments, return value, environment
A Unix C program is invoked by calling its main() function with:
I
a list of strings argv as an argument
I
a list of strings environ as a predefined global variable
#include <stdio.h>
extern char **environ;
Environment strings have the form
name =value
int main(int argc, char **argv)
{
int i;
printf("Command line arguments:\n");
for (i = 0; i < argc; i++)
puts(argv[i]);
printf("Environment:\n");
for (i = 0; environ[i] != NULL; i++)
puts(environ[i]);
return 0;
}
where name is free of “=”.
Argument argv[0] is usually the
name or path of the program.
Convention: main() == 0 signals
success, other values signal errors
to calling process.
14