# 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
C Program to get Process ID and Parent Process ID | In Linux, each running task is known as “Process”. Kernal assigns each process running in memory a unique ID called Process ID or PID. PID distinguishes one process from another running process.
The
Get Process ID and Parent Process ID
#include<stdio.h>
#include<unistd.h>
int main()
{
printf("Process ID: %d\n", getpid() );
printf("Parent Process ID: %d\n", getppid() );
return 0;
}
Output:-
Process ID:23118
Parent Process ID:19713
Whenever we run the program a new process is created, Hence output (PID) will be different each time.
From one process we can create another process. To do this fork() library function will be used. fork() split one process into two
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
- Some interesting points in C programming
- C program to get the Process ID and parent Process ID
- Why gets function is dangerous and should not be used
- Undefined reference to sqrt (or other mathematical functions) even includes math.h header
- Remove all characters in a string except alphabet
- Find the frequency of characters in a string
- Count the number of words in a string
- Count lines words and characters in a given text
- Vowel consonant digit space special character Count in C Programming
- String pattern in C language
- C program to search a string in the list of strings
- Sort Elements in Lexicographical Order (Dictionary Order)
- C program to search a string in the list of strings