-
Notifications
You must be signed in to change notification settings - Fork 0
Home
RekaMocsai edited this page May 1, 2023
·
10 revisions
name | library | description | return | required for |
---|---|---|---|---|
readline | readline.h | reads a line from the terminal and returns it | NULL if EOF, empty for empty line, returns text of line as char*, needs to be free'd | reading input from the terminal, allowing it to be edited before processed by shell |
rl_clear_history | readline.h | Clears the history list of previous input | void | Useful for resetting the history list between commands or sessions |
rl_on_new_line | readline.h | reset prompt | ||
rl_replace_line | readline.h | Replaces the current input line with a new one. if empty str: command line buffer is cleared | ||
rl_redisplay | readline.h | display prompt again | ||
add_history | readline.h | Adds a line of text to the history list | void | Useful for adding previously entered commands to the history list |
printf | stdio.h | Outputs text to the console | int (the number of characters printed) | |
malloc | stdlib.h | Allocates a block of memory on the heap (size specified) | void * (a pointer to the allocated memory) | |
free | stdlib.h | Deallocates a previously allocated block of memory | void | |
write | unistd.h | Writes data to a file descriptor | ssize_t (the number of bytes written) | Useful for outputting text and data to files and other output destinations |
access | unistd.h | Tests whether a file exists and can be accessed | ||
open | fcntl.h | Opens a file and returns a file descriptor | int (fd of the opened file) | Used for opening files for reading or writing |
read | unistd.h | Reads data from a file descriptor | ssize_t (the number of bytes read) | Used for reading data from files or other input sources |
close | unistd.h | Closes a file descriptor | int (0 if successful, otherwise -1 ) | Used for closing file descriptors (when no longer needed) |
fork | unistd.h | Creates a related new process (child) by duplicating the calling one (parent) | pid_t In the parent process: the process ID of the child process, while in the child process it returns 0. -1 if error occured. | Used for creating new processes to run shell commands in (otherwise the parent process would be replaced and terminated - ending the program) |
wait | sys/wait.h | Waits for a child process to terminate | pid_t (the process ID of the terminated child) or -1 if no children are there to wait for | Used for synchronizing the execution of multiple processes in a shell |
waitpid | sys/wait.h | Waits for a specific child process to terminate | pid_t (the process ID of the terminated child) | Used for synchronizing the execution of specific child processes in a shell |
wait3 | sys/wait.h | |||
wait4 | sys/wait.h | |||
signal | signal.h | Sets a signal handler function for a specific signal. Sigaction is better but needs a new struct | sighandler_t (the previous signal handler function) | Used for handling signals, such as interrupts or errors |
sigaction | signal.h | Sets a signal handler function with additional options for a specific signal | struct sigaction* (the previous signal action) | Similar to signal(), but provides more options for handling signals |
sigemptyset | signal.h | Initializes a signal set to be empty | int (0 if successful, -1 otherwise) | |
sigaddset | signal.h | |||
kill | signal.h | Sends a signal to a process or group of processes | int (0 if successful, -1 otherwise) | Used for sending a signal to a process, such as terminating it or requesting it to perform a specified action (by sighandler func) |
exit | stdlib.h | Terminates the current process | void | Useful for terminating the shell or a child process when it has finished executing |
getcwd | unistd.h | Gets the current working directory of the process | char* (a pointer to a string containing the directory path) | |
chdir | unistd.h | Changes the current working directory of the process | int (0 if successful, -1 otherwise) | Used for changing the current working directory, which affects the location of file paths used in the shell |
stat | sys/stat.h | Gets information about a file | int (0 if successful, -1 otherwise) | Used for getting information: size, permissions, and modification time |
lstat | sys/stat.h | Gets information about a file, but does not follow symbolic links | int (0 if successful, -1 otherwise) | Similar to stat(), but does not follow symbolic links when getting information about a file |
fstat | sys/stat.h | Gets information about a file from a file descriptor | int (0 if successful, -1 otherwise) | Similar to stat(), but gets information about a file from a file descriptor instead of a file path |
unlink | unistd.h | Deletes a file or symbolic link | int (0 if successful, -1 otherwise) | Used for deleting a file or symbolic link from the file system |
execve | unistd.h | Replaces the current process with a new one. Old process terminates!!! | int (0 if successful, -1 otherwise) | Used for running shell commands by replacing the current process with the one that executes the command |
dup | unistd.h | Duplicates a file descriptor | int (a new file descriptor that refers to the same file | |
dup2 | unistd.h | |||
pipe | unistd.h | |||
opendir | ||||
readdir | ||||
closedir | ||||
strerror | string.h | Gets a string describing an error code | char* (a pointer to a string describing the error code) | |
perror | stdio.h | Prints an error message to stderr with a prefix | void | |
isatty | unistd.h | Checks whether a file descriptor refers to a terminal | ||
ttyname | unistd.h | Gets the name of the terminal device associated with a file descriptor | char* (a pointer to a string containing the name of the terminal) | |
ttyslot | ||||
ioctl | ||||
getenv | stdlib.h | gets an environment variable specified as argument | if found, returns value string, NULL if there is no match | used to find the full path to functions |
tcsetattr | termios.h | Sets the terminal attributes for a file descriptor | int (0 if successful, -1 otherwise) | |
tcgetattr | termios.h | Gets the terminal attributes for a file descriptor | int (0 if successful, -1 otherwise) | |
tgetent | ||||
tgetflag | ||||
tgetnum | ||||
tgetstr | ||||
tgoto | ||||
tputs |
-
Building a simple shell: tutorial explaining how to build a very simple shell from the ground up
-
History of bash: explains quite well how it is structured, but doesn't show code examples