Daemon process in UNIX

Ratings:
(4)
Views:353
Banner-Img
  • Share this blog:

Daemon process

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.

  1. Copy a. out in any of directory path

# cs    /home/b59p2/UNIX/Sys- exec/ a. out   /home /b59p2/bin # a. out

  1. Another way is to update the PATH variable

# PATH = $ PATH : /root/b59p2 /UNIX/sys-exec # a. out

  1. $ / bin/sh -c command
  2. $ command

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.    

 Assignments

  1. create an executable named “cme exec ” , which when used with the i/p command , should be also to execute the command specified..the command is provide from the command line Vi ass1.c

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

  1. a. out ass1.c cmd exec

p1.c p2 p2.c    

Using exec () call

  #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); }  

  1. Q. a. p to accept any number of commands from the command line and execute them in the same sequence as they are provided.

 

Using system () call

  #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

  1. out ass1.c ass2. C ass3. C cmd exec  cmd sys p1.c p2 thu Aug 12  00:28:23 1st 2010

August 2010 Mon   tue wed  thu   fri  sat

About Author
Authorlogo
Name
TekSlate
Author Bio

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.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox