Linux Process Control With C
Linux Process Control With C
Linux Process Control With C
Process in linux
•
Exec
–
wait
–
FORK
•
When a user attempts to log in, getty wakes up and fork execs
the login program to verify the login name and the password
enterd.
•
Init goes off to sleep, waiting for the death of its children.
Other processes getty and login self extenguish by overlaying.
•
When user logs off his shell is killed and is intimated to init.
init getty shell
fork Fork-exec login Fork-exec
Zombie process
•
int main( )
{
printf ( "Process ID = %d", getpid( ) ) ;
return 0;
}
Parent and Child process
From a running process we can create another process hence creating
a parent child relationship between the existing and newly created
process.
We can do this by a library function called fork().
# include <stdio.h>
# include <sys/types.h> Output :
int main( ) Before Forking
{ After Forking
printf ( "Before Forking\n" ) ; After Forking
fork( ) ;
printf ( "After Forking\n" ) ;
}
•
Ls –al /etc
•
Also note that printf () will not be executed since execl() function
overwrites the image of the calling process with the code and
data of the program to be executed.