diff --git a/README.md b/README.md index 444557c9..2d38c077 100644 --- a/README.md +++ b/README.md @@ -25,104 +25,90 @@ Test the C Program for the desired output. ## C Program to print process ID and parent Process ID using Linux API system calls +``` +#include +#include +#include +int main(void) +{ //variable to store calling function's process id + pid_t process_id; + //variable to store parent function's process id + pid_t p_process_id; + //getpid() - will return process id of calling function + process_id = getpid(); + //getppid() - will return process id of parent function + p_process_id = getppid(); + //printing the process ids +//printing the process ids + printf("The process id: %d\n",process_id); + printf("The process id of parent function: %d\n",p_process_id); + return 0; } +``` +### OUTPUT - - - - - - - - - -##OUTPUT - - - - - - - - - - - - - - +![alt text]() ## C Program to create new process using Linux API system calls fork() and exit() - - - - - - - - - - - - -##OUTPUT - - - - - - - +``` +#include +#include +#include +#include +#include +int main() +{ int pid; +pid=fork(); +if(pid == 0) +{ printf("Iam child my pid is %d\n",getpid()); +printf("My parent pid is:%d\n",getppid()); +exit(0); } +else{ +printf("I am parent, my pid is %d\n",getpid()); +sleep(100); +exit(0);} +} + +``` +### OUTPUT + +![alt text]() ## C Program to execute Linux system commands using Linux API system calls exec() family - - - - - - - - - - - - - - - - - - - - - - - - - -##OUTPUT - - - - - - - - - - - - - - - - - - +``` + +#include +#include +#include +#include +#include +int main() +{ int status; + printf("Running ps with execlp\n"); + execl("ps", "ps", "ax", NULL); + wait(&status); + if (WIFEXITED(status)) + printf("child exited with status of %d\n", WEXITSTATUS(status)); + else + puts("child did not exit successfully\n"); + printf("Done.\n"); +printf("Running ps with execlp. Now with path specified\n"); + execl("/bin/ps", "ps", "ax", NULL); + wait(&status); + if (WIFEXITED(status)) + printf("child exited with status of %d\n", WEXITSTATUS(status)); + else + puts("child did not exit successfully\n"); + printf("Done.\n"); + exit(0);} + +``` +### OUTPUT +![alt text]() # RESULT: The programs are executed successfully.