LinuxQuestions.org
Visit Jeremy's Blog.
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 10-07-2014, 07:45 AM   #1
sumncguy
Member
 
Registered: Jun 2013
Posts: 76

Rep: Reputation: Disabled
Interesting Behavior


Im taking a Linux Essentials class at a local community college. Ive been using the command line for some time in one nix environment or another. Im ok .. but I want to fill in the blanks and LPI cert. Anyway ... this was on a lab. The professor didn't go into detail .. and ironically no other student questioned what was going on...

Quote:
[popeye bin]$ ls -l > file.txt

[popeye bin]$ cat file.txt
total 8
-rw-rw-r-- 1 popeye popeye 16 Oct 7 07:38 file1.txt
-rw-rw-r-- 1 popeye popeye 17 Oct 7 07:38 file2.txt
-rw-rw-r-- 1 popeye popeye 0 Oct 7 07:38 file.txt
Notice the file size of file.txt

Quote:
[popeye bin]$ ls -l file.txt
-rw-rw-r-- 1 popeye popeye 178 Oct 7 07:38 file.txt

[popeye bin]$
I had to think about this for a few minutes.

It looks like the file is created and ls is executed, before the file is written to...

Is there some order of operation going on ?
 
Old 10-07-2014, 08:01 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Your shell is doing this: you are right that creation of the output happens before ls produces the listing.

Code:
receive command from user
fork into two (almost identical but nevertheless distinguishable) processes
  child process:
    redirect stdout to file.txt (creating new empty file)
    execute "ls -l" with stdout as defined above
    and end ... nothing follows successful execution (of ls)

  parent process:
    wait for the child process to end (and observe exit status)
    prompt user for next input
 
  


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
LXer: Interesting new Ubuntu-derived, OS X-inspired distro, interesting revenue (yes, LXer Syndicated Linux News 0 05-01-2009 08:51 AM
very interesting... kessler961 General 9 04-27-2008 04:15 AM
My server was hacked , interesting behavior spotted byteclock Linux - Security 9 12-20-2005 07:36 AM
strange net config behavior - interesting experience... binchin Red Hat 0 09-05-2005 07:07 PM
interesting gmplayer behavior DJOtaku Linux - Software 2 08-12-2005 09:56 AM

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

All times are GMT -5. The time now is 03:16 AM.

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