How to understand the linux kernel practically?

For Example :

I want to know the step by step procedure of the below command ... i mean what goes behind the scenes... what i guess is below ... could you please correct it and provide me correct order please....

If i execute a command $ lpr <<file_name>> in a shell.... what i guess was

1). First shell creates process with a same name i.e. by the command name itself(correct me if i was wrong).....

2). If single process is not sufficient to achieve the exact output..then shell itself(correct me if i was wrong) spawns the child processes and calls the wait4() system call until the child process completes successfully... i mean it gets the exit status of the child. ( Correct me if i was wrong)

3). command $lpr <<file_name>>...since the process need to communicate with the printer....and shell is not able to contact with the hardware....because kernel is the only point of contact to the Hardware....(correct me if i was wrong)..

4).Shell tells to kernel via system calls (correct me i was wrong) that please contact the particular printer and prints that file.

5). After that via the system calls kernel contact back to the shell saying that printing action is over....and generates output in shell as printing done successfully(correct me if i was wrong).


I thought those things happened in the background... But in some books i have read that kernel only will manages to create all the processes and manages memory and resources....How i don't know?

Could you please tell me by considering above example...were the shell works and were the kernel works please.....

I am very much interested to learn the behavior of the shell and kernel.
LVL 1
BharathKumarRaju DasaraRajuDevops EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Assuming the <<>> are meant to be your way of quoting file_name, and not shell here doc redirection,
shell forks a process which executes the system library function
  execlp("lpr","file_name",0); // or the equvalent execve
the lpr process then tells the kernel via system calls that contact the particular printer and prints that file
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
@ozo

you are right its << >> indicates file name only...

I need clear understanding of what goes on behind when i hit enter after typing the command as below.... please
 
    $lpr <<file_name>>
0
ozoCommented:
the shell forks a process which executes the system library function
  execlp("lpr","file_name",0); // or the equvalent execve
the lpr process then tells the kernel via system calls that contact the particular printer and prints that file

see
man execve
for more information about how the execve system call works
see
man lpr
for more information about how the lpr command works
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
@ozo

Thanks for the answer.....how the processes are created to achieve the task......whether shell creates the process or kernel...

i know that fork() system call cretaes the process......but how who asks fork() system call to execute it
0
ozoCommented:
The shell uses the fork() system call to invoke the kernel to create a process
0
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
@ozo .... Thanks for the information.... the sequence which i told is correct or not?
0
ozoCommented:
1) I'm not sure what you mean by this
2) If the command is not a shell builtin command, the shell always forks a process to execute the command
3) I interpret this to mean that the child process does the exec system call
4) The lpr process, not the shell process prints the file via system calls, but the sequence is correct
5) when the lpr process exits, the wait system call returns
0
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
@ozo.....could you give me any practical example to understand better shell and kernel please
0
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
could you please give me any link to better understand the shell and kernel?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.