Prompt Detail:
Here's a list of definitions for all functions used in the simple UNIX shell:
main
:- Definition: The entry point of the C program, responsible for running the shell loop.
- Return: An integer, 0 on successful execution, other values on errors.
read_input
:- Definition: Reads user input from the standard input.
- Return: A pointer to the input string, or NULL on end of file.
execute_command
:- Definition: Executes a command using a forked child process.
- Parameters: A pointer to a character (a string), representing the command to execute.
- Return: None.
malloc
:- Definition: Allocates memory of the specified size and returns a pointer to the first byte of the allocated memory.
- Parameters: Size of memory to be allocated.
- Return: A pointer to the allocated memory, or NULL if allocation fails.
free
:- Definition: Frees the memory previously allocated by malloc, calloc, or realloc.
- Parameters: A pointer to the memory block to be freed.
- Return: None.
strdup
:- Definition: Duplicates a given string by allocating memory for a new copy and copying the characters from the original string.
- Parameters: A pointer to the original string.
- Return: A pointer to the duplicated string, or NULL if memory allocation fails.
printf
:- Definition: Prints formatted output to stdout.
- Parameters: Format string and additional arguments based on the format string.
- Return: The number of characters printed, or a negative value on error.
perror
:- Definition: Prints a descriptive error message to stderr.
- Parameters: A string describing the error context.
- Return: None.
exit
:- Definition: Terminates the program and returns a status value to the parent process.
- Parameters: An integer status value.
- Return: None.
fork
:- Definition: Creates a new child process by duplicating the calling process.
- Return: The process ID of the child process in the parent process, 0 in the child process, or -1 on error.
execlp
:- Definition: Replaces the current process image with a new process image specified by a file path, and searches the directories listed in the PATH environment variable for the specified file.
- Parameters: The file path of the new process image, the command to run, followed by a NULL pointer.
- Return: -1 on error, and does not return on success.
wait
:- Definition: Suspends the calling process until one of its child processes terminates.
- Parameters: A pointer to an integer to store the child process termination status.
- Return: The process ID of the terminated child process, or -1 on error.
getline
:- Definition: Reads a line from the specified stream and stores it in a buffer.
- Parameters: A pointer to the buffer, a pointer to the buffer size, and the input stream.
- Return: The number of characters read, including the delimiter character, or -1 on failure or end of file.
Add a comment