|
521 | 521 | \item runs a program defined via \emph{path} |
522 | 522 | \item arguments that follow, including \emph{arg0}, are given to the program via |
523 | 523 | \texttt{argc} and \texttt{argv} of its \texttt{main()} |
524 | | -\item the argument list must end with \texttt{(char *)0}, ie. \texttt{NULL} |
525 | | -\item \emph{arg0} should contain the program name (ie. not the full path) |
| 524 | +\item the argument list must end with \texttt{(char *)0}, i.e. \texttt{NULL} |
| 525 | +\item \emph{arg0} should contain the program name (i.e. not the full path) |
526 | 526 | \item \emsl{open file descriptors are unaffected by \funnm{exec}} |
527 | 527 | \begin{itemize} |
528 | 528 | \item \dots{}aside from file descriptors with flag \texttt{FD\_CLOEXEC} |
|
541 | 541 | is not important for the sake of a discussion. |
542 | 542 | \item Sometimes \texttt{argv[0]} is different from the executable file name. |
543 | 543 | For example, \texttt{login} command prefixes the shell file name with |
544 | | -\texttt{'-'}, eg. \texttt{-bash}. The shell then knows it is supposed to |
| 544 | +\texttt{'-'}, e.g. \texttt{-bash}. The shell then knows it is supposed to |
545 | 545 | function as a login shell. A login shell reads \texttt{/etc/profile}, for |
546 | 546 | example. |
547 | 547 | \item \funnm{exec} does not transfer the control to the program in memory |
|
623 | 623 | \end{slide} |
624 | 624 |
|
625 | 625 | \begin{itemize} |
626 | | -\item \emsl{l} = list (ie. list of arguments), \emsl{v} = vector (ie. an array |
627 | | -of string pointers), \emsl{e}~=~environment (ie. environment variables are |
| 626 | +\item \emsl{l} = list (i.e. list of arguments), \emsl{v} = vector (i.e. an array |
| 627 | +of string pointers), \emsl{e}~=~environment (i.e. environment variables are |
628 | 628 | passed to the function via an argument), \emsl{p} = \texttt{PATH} is used. |
629 | 629 | \item Aside from \funnm{execlp} and \funnm{execvp}, it is always needed to use |
630 | 630 | the full path to the executable program, either an absolute or relative one. |
631 | 631 | \item All variants aside from \funnm{execle} and \funnm{execve} |
632 | 632 | are also passing to the program being executed the environment variables of the |
633 | | -calling process, ie. the \texttt{environ} array. |
| 633 | +calling process, i.e. the \texttt{environ} array. |
634 | 634 | \item For some unknown historical reasons, there is no ``p'' with ``e'' together |
635 | 635 | in the standard. However, GNU provides \funnm{execvpe} as an extension. |
636 | 636 | \item \label{EXEC_DATE} Example: \example{exec/exec-date.c} |
|
697 | 697 |
|
698 | 698 | \begin{itemize} |
699 | 699 | \item The UNIX standard does not specify what executable file format systems |
700 | | -should use. While most of the UNIX and Unix-like systems (eg. Linux |
| 700 | +should use. While most of the UNIX and Unix-like systems (e.g. Linux |
701 | 701 | distributions) use ELF, there are other widely used systems that do not. One |
702 | 702 | example is macOS (which is a certified UNIX system) that uses the \emph{Mach-O} |
703 | 703 | file format, short for \emph{Mach Object}. Each Mach-O file is made |
|
850 | 850 | \item producer blocks on writing if the pipe is full |
851 | 851 | \item consumer blocks on reading if the pipe is empty |
852 | 852 | \end{itemize} |
853 | | -\item consumer gets EOF (ie. \texttt{read()} returns |
| 853 | +\item consumer gets EOF (i.e. \texttt{read()} returns |
854 | 854 | \texttt{0}) only if all copies of \texttt{fildes[1]} are closed. |
855 | | -\item named pipe (ie. fifo, see \funnm{mkfifo}) works the same way. The |
| 855 | +\item named pipe (i.e. fifo, see \funnm{mkfifo}) works the same way. The |
856 | 856 | difference is any process can use it. |
857 | 857 | \end{itemize} |
858 | 858 | \end{slide} |
|
866 | 866 | u{}nix-domain socket. However, such a workaround is out of scope for this |
867 | 867 | class. |
868 | 868 | \item If the function \funnm{write} writes at most \texttt{PIPE\_BUF} bytes to |
869 | | -the pipe, it is guaranteed that the write will be atomic, ie. such bytes will |
| 869 | +the pipe, it is guaranteed that the write will be atomic, i.e. such bytes will |
870 | 870 | not be intermingled with bytes written by other producers. |
871 | 871 | \item \label{TWO_WAY_PIPES} The SUSv3 standard does not specify whether |
872 | 872 | \texttt{fildes[0]} is also open for writing and if \texttt{fildes[1]} is also |
|
908 | 908 | \funnm{pipe}, we have to call \texttt{dup2(pd[1], 1)} in the producer as |
909 | 909 | otherwise \texttt{dup(pd[1])} could reuse the file descriptor \texttt{0} in |
910 | 910 | place of expected \texttt{1}. You might also need to check if \verb#pd[1] == 1# |
911 | | -(ie. standard output was closed before calling \funnm{pipe}) as in that case we |
| 911 | +(i.e. standard output was closed before calling \funnm{pipe}) as in that case we |
912 | 912 | could actually close one end of the pipe. Similarly, in the consumer you might |
913 | 913 | need to check if \verb#pd[0] == 0#. |
914 | 914 | \item It is better to create a pipe from a child to its parent as typically the |
915 | 915 | process writing the pipe finishes first, then the consumer reads the rest of the |
916 | 916 | data, processes it, and then finally exits. Remember, the shell waits for the |
917 | | -program it started, ie. the parent, and it does not care at all about children |
| 917 | +program it started, i.e. the parent, and it does not care at all about children |
918 | 918 | the running program spawned during its life. If the pipe was created the other |
919 | 919 | way around, the shell could print the prompt after the parent finished while the |
920 | 920 | data from the child might still be flowing to the console. |
|
924 | 924 | was formed. Ie. the first command in the pipeline was created as the last |
925 | 925 | process. |
926 | 926 | \item However, in \texttt{bash}, all processes in a pipeline are direct children |
927 | | -of the shell itself, ie. \texttt{bash} calls \funnm{fork} that many times as is |
| 927 | +of the shell itself, i.e. \texttt{bash} calls \funnm{fork} that many times as is |
928 | 928 | the number of programs in the pipeline. Before the prompt is printed, it waits |
929 | 929 | for all processes it directly created to finish. |
930 | 930 | \end{itemize} |
|
1211 | 1211 | For \funnm{dlopen}, the default is \texttt{RTLD\_LOCAL}. It means you can |
1212 | 1212 | map the same library multiple time via \funnm{dlopen} and the symbols in the |
1213 | 1213 | mapped instances of the same library will not overlap. However, all |
1214 | | - globally mapped symbols from there are shared, eg. \texttt{errno}. |
| 1214 | + globally mapped symbols from there are shared, e.g. \texttt{errno}. |
1215 | 1215 | \end{itemize} |
1216 | 1216 | \item \label{RTLD_NEXT} Special handle \texttt{RTLD\_NEXT} searches the symbol |
1217 | 1217 | only in libraries loaded after the library that called \funnm{dlsym}. Handy for |
|
0 commit comments