# C PROGRAMS
Pointers Examples
➤ Pointer Basic Examples
➤ Dynamic Memory Allocation
➤ Read Write Array with Pointer
➤ Sum Avg of Array with Pointer
➤ Sort Array with Pointer
➤ Search in Array using Pointer
➤ Sum of N Numbers
➤ Largest Number by DMA
Others
➤ C Program Without Main()
➤ Hello World Without ;
➤ Process & Parent Process ID
➤ C Program Without Header File
➤ void main(), main() vs int main()
➤ fork() function in C
➤ Why gets function is dangerous
➤ Undefined reference to sqrt
Previously, we get Process ID or PID and Parent process ID using C programming. Now, we will see fork() in C. In Linux, each running task is known as “Process”.
From one process we can create another process. To do this fork() library function will be used. fork() split one process into two processes:- parent
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
printf("Before Forking\n");
fork();
printf("After Forking\n");
printf("Hello world!\n");
printf("Linux\n");
return 0;
}
Output:-
Before Forking
After Forking
Hello world!
Linux
After Forking
Hello world!
Linux
Note that after fork() all statements executed twice, one by the parent process and another by the child process.
Linux internally uses to fork() to create a new child process. There will be a tree-like structure of all the processes running in the memory. The father of all these
$ ps -A
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Also Learn
- C Program Without Main() Function
- Print hello world without using semicolon
- Get the Process ID and parent Process ID
- fork() in C
- Why gets function is dangerous and should not be used
- Undefined reference to sqrt (or other mathematical functions) even includes math.h header
- Find the length of String
- Copy two Strings
- Concatenate Two Strings
- Compare two strings
- Reverse a String
- Find string is a palindrome or not
- Search position of Nth times occurred element in array
- Remove all characters in a string except alphabet
- Find the frequency of characters in a string
- C program to count the number of words in a string
- C program to count lines words and characters in a given text
- Vowel consonant digit space special character Count in C Programming
- String pattern in C language
- Uppercase character into the lowercase character
- Lowercase character into the uppercase character
- C program to search a string in the list of strings
- Sort Elements in Lexicographical Order (Dictionary Order)