- Process:
- Definition: A process is an instance of a running program. It includes the program code, current activity, a stack, a heap, and other resources.
- Explanation: Think of a process as a single task that your computer is working on. When you open a program, like a web browser or a game, your computer creates a process to handle everything that program needs to do.
- pipe():
- Definition:
pipe()
is a system call that creates a unidirectional communication channel between two file descriptors: one for reading and one for writing.
- Explanation: Imagine a pipe as a tube with two ends. You can put information in one end, and it comes out the other. In programming,
pipe()
creates this tube so two parts of your program can send data to each other.
- fork():
- Definition:
fork()
is a system call that creates a new process by duplicating the current process. The new process is called the child process, and the original is the parent process.
- Explanation:
fork()
is like making a copy of yourself. The copy (child process) can do different tasks from the original (parent process). Both can run at the same time, allowing your program to do multiple things at once.
- dup2():
- Definition:
dup2()
is a system call that duplicates one file descriptor to another, closing the target descriptor first if necessary.
- Explanation: Imagine you have a TV remote (file descriptor) that controls one TV (resource).
dup2()
is like reprogramming the remote so it now controls a different TV. In programming, it changes where input or output goes, like redirecting data from a file to the screen or vice versa.
- access():
- Definition:
access()
is a system call that checks the accessibility of a file (e.g., if it exists, if you can read or write it).
- Explanation:
access()
is like checking if a door is locked before you try to open it. In programming, it helps you check if you can read, write, or execute a file before you try to use it.
- access():
- Definition:
execve()
is a system call that runs a new program in the current process. It replaces the current process image with a new one specified by the program path, along with the given arguments and environment variables.
- Explanation in Context: In your code,
execve()
is used to run commands. When execve()
is called, it takes the command you want to run (like /bin/ls
or /usr/bin/grep
) and executes it in the current process. This means your process stops running the existing code and starts running the command you specified.
- waitpid():
- Definition:
waitpid()
is a system call that makes the parent process wait until a specific child process terminates. It can also retrieve the exit status of the child process.
- Explanation in Context:
waitpid()
would be used to ensure that the parent process waits for the child process to complete before proceeding. This is crucial when you need to ensure that the parent process does not continue until the child has finished its task.