Giter Site home page Giter Site logo

pipex's Introduction

pipex

Check

use valgrind --track-fds=yes to check if all fds are properly closed.

check memory leak when error encountered.

Fact

every process has their own file descriptor system, including STDIN and STDOUT

open("file", O_CREAT | O_WRONLY | O_TRUNC) is the same as creat("file")

pipe()

first initialize a int fd[2], then make it a pipe pipe(fd)

the pipe is a ONE way communication tool.

fd[0] refers to the read end of the pipe. (IN)

fd[1] refers to the write end of the pipe. (OUT)

pipe() returns 0 on success, returns -1 on error.

fork()

fork() returns the child pid in parent process, returns 0 in the child process

##dup2()

dup2(fd[1], STDOUT_FILENO) redirect the stdout to fd[1], so whatever originally output to the terminal(stdout) will go to the pipe.

execve

exec family replace the process image, statment after exec will only be executed in case of error

if (execve(SOMETHING) == -1)
  perror("error");

access()

int access(const char *pathname, int mode);

F_OK check for the existence of the file

W_OK R_OK X_OK check for write, read and execute permission respectively

access return 0 on success, -1 when fail for mode check (the file does not exist when F_OK is flagged)

Useful link

https://blog.csdn.net/wh128341/article/details/125906940 dup2 redirection, fd system, linux file system, inode, hard soft link, hard disk principle, (Chinese)

pipex's People

Contributors

chltam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.