#include <stdio.h> #include <unistd.h> int main() { pid_t child_pid; // Fork the current process child_pid = fork(); // Code that runs in both parent and child processes if (child_pid > 0) { // This code is executed by the parent process printf("Parent process (PID=%d) created child process (PID=%d)\n", getpid(), child_pid); } else if (child_pid == 0) { // This code is executed by the child process printf("Child process (PID=%d) created by parent process (PID=%d)\n", getpid(), getppid()); } return 0; }
Write, Run & Share Bash code online using OneCompiler's Online Bash Shell for free. It's one of the robust, feature-rich Bash shell available over online and getting started with the OneCompiler's Bash Shell is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Bash
. OneCompiler also has reference scripts, where you can look for the sample scripts and start coding.
Bash (Bourne Again Shell) is a shell program written by Brian Fox and is an upgraded version of Bourne Shell program 'sh'.
name="Foo"
echo $name
echo "$name"
echo "${name}"
if [ conditional-expression ]
then
statements
fi
if [ conditional-expression ]
then
statements
else
statements
fi
if [ conditional-expression ]
then
statements
elif [ conditional-expression ]
then
statements
else
statements
fi