At TTY – if we observe ‘?’ , it indicates it a Daemon process, which does not need any input and automatically comes into life when the OS is switched ON. And the processes can be seen using commands. Gnome – terminal Is the parent for the bash. Example on System () call Vi p1.c #include <stdio.h> #include <stdlib.h> Main () { Print f (“Process id = % d………parent id = %d /n”, get p id (), get p p id ()) System (“./p2 ”);// p2 is executable file of p 2.c Print f (“After system () call came back to process 1 ”); } Vi p2.c #include <stdio.h> #include <stdlib.h> Main () { Print f (“Process id = % d………parent id = %d /n”, get p id (), get p p id ()); } Cc -0 p2 p2.c Creates executable for p2.c with name p2. Output cc p1.c # ./a.out Process 1 id = 2963 ……….parent id = 2767 à this is PID of gnome – terminal Process 2 id = 2964……….parent id = 2763 à this is PID process 1 as process1, called process 2 After System () call came back to process 1 . $echo $PATH / user/ Kerberos/bin : /ur/local/bin :/bin : /user/bin : /home /b59p2/bin These are the paths available in the terminal if we have two executes like ls, cal etc……… Simply by $ ls, $ cal we can execute, but even through a. out is an executable , $ a. out does not executes why ? $ . pwd /home/b59p2/UNIX/Sys – exec This is path of you’re a .out, Which is not available in above shown paths. Hence, it searches for a. out there in above paths & hence not found, Results, bash : a. out : command not found. Now to execute directly like # a. out , we have two solutions.
# cs /home/b59p2/UNIX/Sys- exec/ a. out /home /b59p2/bin # a. out
# PATH = $ PATH : /root/b59p2 /UNIX/sys-exec # a. out
Ex :- $/bin / sh -c ls $ ls Both generates same output Here the major difference is that, in first command bash creates sh and executes command is returns. In 2nd statement executes command in present shell Bash is parent.
Using System () call #include <stdio . h> #include <stdlib . h> Main (int argc, char ** argc ) { If (argc ! = 2) { Print f (“usage ./cmd exec <command >” ); Return; } System ( arg v [1]); } creating executable cc -0 cmd exec ass1.c Output ./cmd exec ls
p1.c p2 p2.c
#include <stdio. h> #include <stdlib. h> Main (int arg c , char ** arg v) { If (argc ! 2) { Print f (“Usage : ./cmd exec <command> ”); Return ; } Execlp ( args v [1], argv [1], NULL); }
#include <stdio. h> #include <stdlib. h> Main (int arg c , char ** arg v) { Int I ; If (argc == 2) { Print f (“Usage : ./a. out <command 1> <command 2> ………….”); Return ; } For (I =1 ; argv [i] ; I ++ ) System (arg v [i] ); } Output ./a .out ls date cal
August 2010 Mon tue wed thu fri sat
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.