Prompt Title: Definitions for all needed functions for step 1 of shell (MAYBE)

Created 1 year ago
Votes 0
Views 143 times
0

Prompt Detail:

Here's a list of definitions for all functions used in the simple UNIX shell:

  1. 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.
  2. read_input:

    • Definition: Reads user input from the standard input.
    • Return: A pointer to the input string, or NULL on end of file.
  3. 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.
  4. 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.
  5. free:

    • Definition: Frees the memory previously allocated by malloc, calloc, or realloc.
    • Parameters: A pointer to the memory block to be freed.
    • Return: None.
  6. 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.
  7. 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.
  8. perror:

    • Definition: Prints a descriptive error message to stderr.
    • Parameters: A string describing the error context.
    • Return: None.
  9. exit:

    • Definition: Terminates the program and returns a status value to the parent process.
    • Parameters: An integer status value.
    • Return: None.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
avatar
Night8Guy
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

0
0
Zsh 自動補全功能
1 year ago 2023-03-27 04:08:48 raiven.kao