Skip to content

AijaRe/42Porto_pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipex

Program execution: ./pipex infile cmd1 cmd2 outfile

Infile and outfile - file names

cmd1 and cmd2 - shell commands with their parameters

The program should behave as the shell command < infile cmd1 | cmd2 > outfile

Example: ./pipex infile "grep a" "cat -e" outfile should behave like < infile grep a | cat -e > outfile

Materials:

Playlist on Unix processes from Code Vault

Write your own Shell playlist

Pipex tutorial - Medium

Reactive guide with some edge cases

Pipex explained (in Russian)

Error handling

Exit

Wait, waitpid

Pipe explained

Execve explained

Pipex Plan (mandatory):

Validate the input.

Open the infile. Check access rights. Redirect to standard input.

Create path array from env.

Create pipe.

Fork the process.

Child process deals with command 1.

  • Redirect the stdout to pipe.

  • Get path.

  • Check path access.

  • Split the command input.

  • Execve the path and command 1.

Parent process deals with command 2.

  • Redirect the stdin to pipe.

  • Open / create the outfile. Redirect to stdout.

  • Get path.

  • Check path access.

  • Split the command input.

  • Execve the path and command2.

Misc comments

fork() returns PID of the child process to the parent.

Find command path with whereis.

Check your fds currently open with the command ls -la /proc/$$/fd

To see what is inside envp, type env in your terminal.

Norminette

This project has to be written in accordance with the Norm, which is the coding standard of the school 42.

The Norm includes:

  • Forbidden: for, do...while, switch, case, goto, ternary operators and variable-length arrays
  • Maximum of 25 lines per function
  • Maximum line length: 80 columns
  • Maximum 4 parameters per function
  • Variable assignments and declarations must be on separate lines
  • etc...

Line PATH in env contains all possible paths to the command binaries. PATH=/nfs/homes/arepsa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Split, using : as delimiter. Add a / at the end for the path to work correctly.

Valgrind check with --trace-children=yes.

About

Unix processes in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published