« first day (1933 days earlier)      last day (1490 days later) » 

4:57 AM
So, who is snowed in today?
 
5:34 AM
@mikeserv So, difference is that one is C loop and second is Shell loop right?
 
@Pandya - that's one difference. it is not the most significant though. do: strace yes >/dev/null and then strace sh -c 'while echo y; do echo y; done' >/dev/null
look at the size of the output blocks for each write()
every write() is a context switch into kernel space.
 
The big difference is that one of them makes 1,024 times as many writes as the other, and probably reopens and closes the file each time too
 
@MichaelHomer - it shouldn't do an open() every time i wouldn't think.
but yeah, it will do a write for every two bytes.
 
strace it!
 
really?
 
5:44 AM
bash does, at the very least: open("a", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3, over and over again
 
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
write(1, "y\n", 2) = 2
 
dash too
 
^ that's dash right there.
 
@mikeserv `strace yes >/dev/null` giving:
write(1, "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"..., 4096) = 4096

whereas `strace sh -c 'while echo y; do echo y; done' >/dev/null` giving:
write(1, "y\n", 2) = 2
But I don't know about the output; can you introduce/help it? @mikeserv
 
open("a", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_GETFD)                       = 0
fcntl(1, F_DUPFD, 10)                   = 10
fcntl(1, F_GETFD)                       = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
dup2(3, 1)                              = 1
close(3)                                = 0
write(1, "y\n", 2)                      = 2
dup2(10, 1)                             = 1
fcntl(10, F_GETFD)                      = 0x1 (flags FD_CLOEXEC)
close(10)                               = 0
That's bash. It seems needlessly complicated even for reopening every time.
 
5:48 AM
@Pandya - yeah, see? so the yes loop will fill out a whole page of memory before attempting to to write it to a file.
Yes.
@MichaelHomer - i completely agree, and want to say so much more.
there may be a difference between my dash and yours though in that mine is statically compiled against musl.
 
@mikeserv (consider me as newbie in case of block size and page of memory). write output "2" and"4096" are the size of block?
 
dash, still too complicated:
open("a", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
fcntl(1, F_DUPFD, 10) = 10
close(1) = 0
fcntl(10, F_SETFD, FD_CLOEXEC) = 0
dup2(3, 1) = 1
close(3) = 0
write(1, "y\n", 2) = 2
dup2(10, 1) = 1
close(10) = 0
open("a", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
Yes, size of the written data
 
@Pandya - what ^ he said. that's the total byte count for the string argument to write().
 
@mikeserv ok
BTW, I've started to read wikipedia's article on Block and Data buffer. Welcome to suggest site/web-pages which gives information on such topics that is recommended to new-users in this (block,buffer) field.
 
i suggest you... keep it up? i dunno. i learned most of what i know about that stuff by screwing things up, but it feels kinda weird suggesting you follow suit...
 
6:39 AM
@mikeserv That sounds like how most of us learn.
 
@FaheemMitha - well, of course, but it seems a little weird to say things like: Go forth and fuck up.
then again, maybe thats why actors say break a leg?
 
@mikeserv That should probably be in the Bible, if it isn't already.
But maybe "go forth and procreate" is an acceptable substitute.
So, any snow/ice news?
 
what? in san diego?
 
@mikeserv Oh, I didn't mean you personally. Though snow in SD would definitely be news. Probably a sign of the End Times.
 
yeah, it's no mumbai, but it doesnt get a lot of snow either.
 
6:45 AM
Bombay, not Mumbai. Yuck.
 
theyre both hot, right?
 
Anthony has a cam set up pointing to his deck. But I expect he's asleep right now.
@mikeserv They are.
But not in the sexy way. Just to be clear.
 
oh. he gets a lot of snow. i think he's in germany...?
hahaha
 
@mikeserv No, VA. Don't you Americans recognize each other?
I mean, you need a Masonic handshake or something.
 
hmmm. you mean - by font?
 
6:47 AM
Well, lunch time. Toodles.
@mikeserv Or that.
Masonic fonts. Hmm.
 
ok... yes. there would be a lot of triangles and eyeballs, i expect.
enjoy the grub.
 
Probably.
 
 
2 hours later…
8:29 AM
I am planning to post a question like: How do I timeout the for/while loop? or How do I execute for/while loop for the specified time? How about such a question in our community?
 
@Pandya - what?
 
@Pandya You mean like for a prescribed amount of time, or a determined number of loops? If the former, use sleep, for the latter use a counter.
But that isn't shell-specific, surely.
 
@mikeserv like: How do I run for/while loop for specific time period?
 
No, actually sleep might not cut it. Use case, please.
 
@Pandya - did you see the edit i made on my answer to your question?
@FaheemMitha - i wouldn't think it is shell specific.
 
8:36 AM
@mikeserv Yes, except that I don't know what he is going for, exactly.
 
@FaheemMitha - and yeah, i just did it with sleep there.
 
@mikeserv If you know the context, you're ahead of me.
 
You mean:
for cmd in exec\ yes 'while echo y; do :; done'
do set +m
sh -c '{ sleep 1; kill "$$"; }&'"$cmd" | wc -l
set -m
done
@mikeserv ^^?
 
yeah.
@FaheemMitha
1
Q: How does `yes` write to file so quickly?

PandyaLet me give an example: $ timeout 1 yes "GNU" > file1 $ wc -l file1 11504640 file1 $ for ((sec0=`date +%S`;sec<=$(($sec0+5));sec=`date +%S`)); do echo "GNU" >> file2; done $ wc -l file2 1953 file2 Here you can visualize that the command yes writes 11504640 lines within a second whereas I c...

 
@mikeserv Thanks.
 
8:39 AM
@Pandya - well that's one for loop, but the method would be the same.
you just have to nest it.
 
@mikeserv Yes, I see kill "$$" . Thanks
+1 from me
@mikeserv Suppose I wan to print "string" in screen for 3 seconds with while true; do echo "string"; done then what should I try?
I've tried for cmd in 'while true; echo "hello"; done'; do sleep 5; kill "$$"; done;
It stops loop after 5 seconds but don't print output on screen
 
8:54 AM
Your loop sets the variable cmd to 'while true ... done;', once, runs sleep 5, and is over.
 
( while : ; do echo string ; done ) & pid=$! ; sleep 3 ; kill $pid
 
@MichaelHomer working. thanks. I was also thinking about killing based on pid but forgot about $!
also had not known about ":"
(yes, Null command is helpful here)
 
9:18 AM
{ ... } - Group commands as a unit.
[ - Evaluate conditional expression.
can you throw light on "(" ?
in Bash.
 
9:43 AM
@Pandya - it calls up a child shell.
In bash, it does, anyway.
basically - it is a copy of the parent, but stuff you do within doesn't affect the parent.
it's also costly - in general forks should not be looped over if it can be avoided sensibly.
in screen?
 
10:20 AM
It isn't really that costly, though. At least not that I've observed. Depends on how many you do, of course.
 
 
1 hour later…
11:22 AM
@FaheemMitha - it's very costly - especially in a loop. in shell loops - if you have to use them - you should be using only builtins as much as possible, and all of the hard stuff should usually be done with some other command.
But look what I mean:
time while echo; do :; done 2>/dev/null | head -n1000 |wc -l 1000
while ,,, done 0.00s user 0.00s system 51% cpu 0.006 total
head -n1000  0.00s user 0.00s system   0% cpu 0.004 total
wc -l              0.00s user 0.00s system 0% cpu 0.003 total
 
@mikeserv I thought you meant that subshells were expensive.
Maybe I misunderstood.
 
yeah im almost there.
the formatting is awful there!
time while (echo); do :; done 2>/dev/null | head -n1000 |wc -l 1000
while ...  0.06s done user 0.53s system 27% cpu 2.190 total
head -n1000  0.01s user 0.03s system 1% cpu 2.179 total
wc -l  0.00s user 0.00s system 0% cpu 2.174 total
thats a ... what?
i guess it is a 4000% increase in completion time or something?
@FaheemMitha - you see?
 
11:51 AM
@mikeserv Yes, I see. But still not significant in terms of total time.
@mikeserv Much more than that.
A several hundred fold difference.
 
12:45 PM
@FaheemMitha - what do you mean by total time? Like 2 seconds isn't all that long? Yeah. Subshells are useful most of all because they enable parallelism though. The best way to do stuff with them is is to stream stuff through them in a separate context. I think so anyway.
 
@mikeserv Yes, 2 seconds isn't that long.
 
But in loops, they're productivity poison.
Well, 2 seconds to write out 1000 is pretty damn long, though.
1000 bytes, that is.
 
I'm not suggesting it's good practice. If it's at the bottom of a big stack of stuff and is run a lot, it's murder, obviously. But for a one-off, no biggie.
 
Yeah, interactive is no big deal - by the time you press enter anf blink its usually done cause you can't type that fast otherwise
But people write programs like that.
And then other people write programs like that which loop over programs like that and so on and so forth.
Its maddening to me.
 
@mikeserv Yes, that sort of thing isn't a great idea.
But one really shouldn't be programming in shell anyway. It doesn't scale.
 
1:06 PM
@Ramnath sounds like you are trying to traverse an enormous directory tree. My guess is that the recursive grep is being run on several thousand files. To make matters worse, you're running the same grep twice. The best way to figure out this sort of thing is to post a question on the main site (not in chat), explaining 1) what you want to happen 2) what actually happens and 3) giving examples of your input files and directories. Something that we can use to reproduce the issue.
 
Hello,
 
Sure it does - it scales excellently - its basically a macrolanguage. And if you work data in streams through pipelines rather than trying hub all the work in your shell you can handle as much data as you can afford electricty to flip its bits. The trick is to design pipelines that start at one end and end at another - the various sections just work their own purposed loop over the stream - forever if you like.
 
@Jacobadtr hi
 
 
2 hours later…
3:23 PM
@mikeserv I meant it doesn't scale to large projects. Many lines of code.
 
@FaheemMitha i guess that depends - it doesnt all need to go in the same file. and if you use your fs a little like a database filename, then commands like ., hash, alias, and command, can turn a script project tree into a self-discovering, run-timr expandable modular library. ...but thats not for everybody...
But youre right shell scripts can get rather unwieldy withoutcareful planning.
 
 
1 hour later…
4:31 PM
@mikeserv Well, I have minimal experience with shell scripting/programming myself. But conventional wisdom holds that shell is not suitable for larger scale programming.
And really, even regular/conventional programming languages with all the bells and whistles don't do so well when it comes to large scale programming. E.g. Python.
 
Python is an abomination. It's not regular or conventional - its... half of my filesystem and i make it a point to avoid python code whenever possible.
It requires virtual environment managers and 3 or 4 versions of its interpreter - and so multiple versions of its environment managers!
 
@mikeserv "half of my filesystem" ??!!
I'm not sure what a virtual environment manager is, but I'm fairly sure I've never used one.
 
Yes, seems like! Its everywhere. That is ridiculous!
How many pythons do you have?
 
If you mean in literal space usage, that's quite unlikely.
@mikeserv Dunno. I'll check.
It looks like 2.6, 2.7, 3.4.
 
I guess this is one of them...
So how do you know which python is python when you python?
 
4:39 PM
@mikeserv Ok. I've never used that, though.
 
And do they all have there own easteregg directory or something?
 
@mikeserv Debian defines a default. python is 2.7. And python3 is 3.4. python2.6 for 2.6, but I don't use that. I'm not sure why it's there. Probably it's there from a previous Debian incarnation/release.
@mikeserv I'm not sure, but I don't think so.
They are just installed in different directories on the filesystem.
I'm not the world's biggest Python fan, or anything, but overall it's a pretty reasonable programming languages. There are far worse things out there.
Except for that annoying whitespace thing.
I invited someone in here. I'm not sure if he's coming.
 
@FaheemMitha i did a find on usr for python and .py files and it came to more than 15k files - and i dont use python. Thats ridiculous.
 
This one looks like a clear VTC:
1
Q: Problem with ssh connection

user2738748I need to connect to my computer via ssh. I have to use VPN, because the remote machine is my computer at my workplace. I have no problems with using VPN. So, I installed open ssh server from the repository (I use ubuntu 14.0). I have a pernament IP address. Then I started the ssh server: ...

 
Whats a vtc?
 
4:47 PM
@mikeserv You're probably using Python programs. What distribution?
@mikeserv Vote To Close.
"Edit2: Now it works - I forgot to change the username."
Not much point keeping this one open.
 
@FaheemMitha its arch linux. I probably am - or else some program i use is built atop another which uses python. But i pointedly avoid installing anything python because there are alreafy 15k files on my disk for its sake that i dont understand - more wont help.
Its just required, i think in base or base-devel or whatever.
 
Well, some system programs use it too, I think.
 
5:18 PM
@FaheemMitha - yeah, i think so. im pretty sure a lot of the red hat stuff does. and on systems with some kind of gnome - which i don't have - i'm pretty sure that count would be doubled at least.
 
@mikeserv Perhaps. Anyway, disk space is cheap these days. I have a zillion files on my hard drive. Personally I don't worry about it.
 
well, i haven't undertaken to clear em out either. but it sure seems extensive to me - the whole framework is just monstrous - and i have three of them too!
but i have 3.5m 3.5 and 2.7
whatever m is.
 
If you think that's monstrous, I wonder what you think of proprietary OSs like Windows. A minimal install is some gigs.
 
@mikeserv: It's minimal, IIRC
 
@cuonglm Why have two separate versions of 3.5?
 
5:29 PM
@cuonglm - hehe.
@FaheemMitha - i hate windows. and i hate seeing the kinds of complexity i would expect on a windows system in my /.
 
@mikeserv Yes, Windows SUX. I think we can all agree on that.
4
 
the several pythons by necessity always reminds me of \Program Files` and \Program Files (x64)`
...or however that goes again...
 
@mikeserv and @FaheemMitha: Well, I remember wrong, the m mean the compiled file used Pymalloc
They're identical in my Debian
 
5:44 PM
@FaheemMitha hope you're still here?
 
 
5 hours later…
10:51 PM
@Alborz Looks like you missed me by 10 minutes or so. It's the middle of the night here, but I should be around tomorrow.
 

« first day (1933 days earlier)      last day (1490 days later) »