LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-19-2021, 12:22 PM   #16
Victor43
Member
 
Registered: May 2020
Posts: 46

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by MadeInGermany View Post
In short:
it forks a subshell that execs into an "ls -a".
Thank you for the response. When you say "execs into an "ls -a" do you mean to say that the subshell calls the function execve() in order to execute the parameter "ls -a" ?
 
Old 07-19-2021, 12:44 PM   #17
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
the return from strace tells you the sequence that happens, simply analyze what it tells you and each step leads to the next.

For example, the first line returned from your "strace ls -a" (on my system) is
Code:
execve("/usr/bin/ls", ["ls", "-a"], 0x7ffd9a4e7948 /* 99 vars */) = 0
which says that the shell calls execve to create the subshell and execute "/usr/bin/ls" (within that sub-shell) with the parameters "ls" and "-a" as $0 and $1, the 0x.... is the memory address to use, the /* ... */ is a comment, and the final "= 0" says it was successful
The remainder of the return is what is done inside the ls command, including the multiple write(....) statements that return the results back to the original shell (your terminal window).

Last edited by computersavvy; 07-19-2021 at 12:54 PM.
 
Old 07-22-2021, 02:40 PM   #18
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Quote:
Originally Posted by Victor43 View Post
Thanks for the response but what does the above mean in layman's terms "forks a subshell" ? Please correct me if I'm wrong but a fork() system call is called which in turn creates a child process that in turn calls system function call execve() which processes the "ls -a" command. Does this sound correct ?

Thanks
Yes, but the execve() is special because the kernel replaces the caller by the called program.
And that is why the shell must fork before - so there is something that can wait and continue.
BTW in Linux the fork() is realized by clone() - in
strace -f
you'll see clone() then execve()
 
1 members found this post helpful.
Old 07-22-2021, 04:33 PM   #19
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
It is wrong end of your problem. Why do you need such things? Just compile hello world program in C. Run it. You obtain all needed information. Besides have some fun. Say
Code:
$ echo 'void main(void) { ; }' > foo.c
$ cc foo.c 
$ ./a.out 
$ echo $?
242
ever hear about error code 242?
Code:
$ strace ./a.out 
execve("./a.out", ["./a.out"], 0x7ffcb9967fd0 /* 59 vars */) = 0
brk(NULL)                               = 0x837000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
...........
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script For Reading User Input then Compressing That Input to Tar file braveranger Linux - Newbie 13 11-15-2017 09:36 AM
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
[SOLVED] Cursor does not move to the bottom line and overwrite to same line on command line mesuutt Linux - Newbie 3 02-25-2012 08:04 AM
[SOLVED] Awk: Input from one line, execute program; input from next line, execute program C.L. Programming 9 09-27-2010 12:06 AM
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration