User Tools

Site Tools


os_cp:fork_exec_pipes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
os_cp:fork_exec_pipes [2025/05/19 22:27]
jkonczak
os_cp:fork_exec_pipes [2026/05/20 20:31] (current)
jkonczak
Line 20: Line 20:
  
 There is a list of things that ''​fork''​ does not clone or that are reset for the There is a list of things that ''​fork''​ does not clone or that are reset for the
-child process upon ''​fork''​. See POSIX standard or Linux manual on fork for details.+child process upon ''​fork''​. 
 +\\ See POSIX standard or 
 +[[https://​man7.org/​linux/​man-pages/​man2/​fork.2.html|Linux manual on fork]] 
 +for details. 
 +\\
 Notice that: Notice that:
   * all stack and heap memory is copied   * all stack and heap memory is copied
Line 160: Line 164:
 <​html><​div style="​margin-bottom:​-1.4em"></​div></​html>​ <​html><​div style="​margin-bottom:​-1.4em"></​div></​html>​
 <code c> <code c>
-char arg0[] = "​ls"; ​    char arg2[] = "​-a";​ 
-char arg1[] = "​-l"; ​    char arg3[] = "/​tmp";​ 
-char *argv[] = {arg0, arg1, arg2, arg3, NULL}; 
 # Argument list: # Argument list:
-execlp("​ls", ​   arg0arg1arg2arg3, NULL); +execlp("​ls", ​          "​ls"​"​-l"​"​-a"​"/​tmp"​, NULL); 
-# Argument vector:+ 
 + Argument vector: 
 +char        *argv[] = {"​ls",​ "​-l",​ "​-a",​ "/​tmp",​ NULL};
 execvp("​ls",​ argv); execvp("​ls",​ argv);
 </​code>​ </​code>​
Line 233: Line 236:
     double elapsedSec = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;     double elapsedSec = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
 </​code>​ </​code>​
 +<​HTML></​div><​div style="​margin-top:​-1.4em"></​HTML>​
 +Instead of the C11 function ''​[[https://​en.cppreference.com/​c/​chrono/​timespec_get|timespec_get]](&//​x//,​ TIME_UTC);'',​ you may also
 +use the POSIX function ''​[[https://​pubs.opengroup.org/​onlinepubs/​9799919799/​functions/​clock_gettime.html|clock_gettime]](CLOCK_MONOTONIC,​ &//​x//​);''​.
 <​HTML></​div></​HTML>​ <​HTML></​div></​HTML>​
 </​small>​ </​small>​
Line 387: Line 393:
 <​small>​Pipe is unidirectional. The unix //socket// is its bidirectional <​small>​Pipe is unidirectional. The unix //socket// is its bidirectional
 equivalent. See ''​[[https://​man7.org/​linux/​man-pages/​man7/​unix.7.html|man 7 unix]]''​ equivalent. See ''​[[https://​man7.org/​linux/​man-pages/​man7/​unix.7.html|man 7 unix]]''​
-for details.</​small>​+for details. 
 +\\ 
 +POSIX standard also defines (but not mandates) 
 +[[https://​man7.org/​linux/​man-pages/​man7/​mq_overview.7.html|message queues]]. 
 +</​small>​
  
 ~~Exercise.#​~~ Write a program that: ~~Exercise.#​~~ Write a program that:
os_cp/fork_exec_pipes.txt · Last modified: 2026/05/20 20:31 by jkonczak