[cs631apue] Sorting working on Linux, but not Unix

Jason Ajmo jajmo at stevens.edu
Fri Sep 29 13:38:13 EDT 2017


And only that one directory, apparently:

[vagrant at vagrant include]$ ../ls -lS
total 40
-rw-r--r--  1 vagrant 1000 2655 Sep 29 16:05 config.h
-rw-r--r--  1 vagrant 1000  758 Sep 28 17:12 print.h
-rw-r--r--  1 vagrant 1000  371 Sep 28 16:29 helpers.h
-rw-r--r--  1 vagrant 1000  306 Sep 28 17:13 sort.h
-rw-r--r--  1 vagrant 1000  278 Sep 19 23:58 ls.h

I made sure to include a 'hidden' file in include/ for testing purposes.

On Fri, Sep 29, 2017 at 1:36 PM Jason Ajmo <jajmo at stevens.edu> wrote:

> Furthermore, it appears the bug only applies to the top-level directory.
>
> i.e.:
> [vagrant at vagrant midterm]$ ./ls -lSR
> total 216
> -rw-r--r--  1 vagrant 1000  1846 Sep 28 16:29 helpers.c
> -rw-r--r--  1 vagrant 1000  3912 Sep 29 17:35 sort.o
> drwxr-xr-x  2 vagrant 1000  4096 Sep 25 17:18 include
> -rw-r--r--  1 vagrant 1000   566 Sep 28 17:00 GNUmakefile
> -rw-r--r--  1 vagrant 1000  3968 Sep 29 17:35 helpers.o
> -rw-r--r--  1 vagrant 1000  1515 Sep 29 17:26 print_recurse.c
> -rwxr-xr-x  1 vagrant 1000 22794 Sep 29 17:35 ls
> -rw-r--r--  1 vagrant 1000  2712 Sep 29 17:35 print_recurse.o
> -rw-r--r--  1 vagrant 1000  3128 Sep 29 17:35 print_dir.o
> -rw-r--r--  1 vagrant 1000  7504 Sep 29 17:35 ls.o
> -rw-r--r--  1 vagrant 1000  7044 Sep 29 16:56 print.c
> -rw-r--r--  1 vagrant 1000  6344 Sep 29 17:33 sort.c
> -rw-r--r--  1 vagrant 1000  3283 Sep 27 16:03 ls.c
> -rw-r--r--  1 vagrant 1000  1620 Sep 29 17:29 print_dir.c
> -rw-r--r--  1 vagrant 1000  1392 Sep 25 17:11 README
> -rw-r--r--  1 vagrant 1000   546 Sep 28 17:00 Makefile
> -rw-r--r--  1 vagrant 1000 11496 Sep 29 17:35 print.o
>
> ./include:
> total 40
> -rw-r--r--  1 vagrant 1000  2655 Sep 29 16:05 config.h
> -rw-r--r--  1 vagrant 1000   758 Sep 28 17:12 print.h
> -rw-r--r--  1 vagrant 1000   371 Sep 28 16:29 helpers.h
> -rw-r--r--  1 vagrant 1000   306 Sep 28 17:13 sort.h
> -rw-r--r--  1 vagrant 1000   278 Sep 19 23:58 ls.h
>
> On Fri, Sep 29, 2017 at 12:53 PM Jason Ajmo <jajmo at stevens.edu> wrote:
>
>> Thanks for clarifying NetBSD vs. Unix.
>>
>> I have verified the function is being executed, but I just found some
>> more interesting behavior. I stuck a print statement in the block where it
>> compares filesizes, and the output is interesting.
>>
>> On NetBSD:
>> Comparing .test: 3 and print.o: 11496
>> Comparing helpers.c: 1846 and .test: 3
>> Comparing sort.o: 3720 and .test: 3
>> Comparing include: 4096 and .test: 3
>> Comparing GNUmakefile: 566 and .test: 3
>> Comparing helpers.o: 3968 and .test: 3
>> Comparing print_recurse.c: 1494 and .test: 3
>> Comparing ls: 22842 and .test: 3
>> Comparing print_recurse.o: 2848 and .test: 3
>> Comparing print_dir.o: 3256 and .test: 3
>> Comparing ls.o: 7504 and .test: 3
>> Comparing print.c: 7045 and .test: 3
>> Comparing sort.c: 6206 and .test: 3
>> Comparing ls.c: 3283 and .test: 3
>> Comparing print_dir.c: 1672 and .test: 3
>> Comparing README: 1392 and .test: 3
>> Comparing Makefile: 546 and .test: 3
>> Comparing print.o: 11496 and .test: 3
>>
>> On Linux:
>> <snip>
>> Comparing include: 4096 and helpers.o: 4152
>> Comparing include: 4096 and print_recurse.o: 3112
>> Comparing print_dir.o: 3664 and print_recurse.o: 3112
>> Comparing helpers.c: 1846 and print_recurse.o: 3112
>> Comparing helpers.c: 1846 and print_recurse.c: 1494
>> Comparing .test: 3 and ls.o: 7888
>> Comparing print.c: 7045 and sort.c: 6206
>> Comparing ls.o: 7888 and print.c: 7045
>> Comparing .test: 3 and print.c: 7045
>> Comparing .test: 3 and sort.c: 6206
>> Comparing ls.c: 3283 and print_dir.c: 1672
>> Comparing Makefile: 546 and print.o: 12800
>> Comparing README: 1392 and print.o: 12800
>> Comparing README: 1392 and Makefile: 546
>> Comparing ls.c: 3283 and print.o: 12800
>> Comparing ls.c: 3283 and README: 1392
>> Comparing print_dir.c: 1672 and README: 1392
>> <snip>
>>
>> So now it's clear why it's not sorting properly. On NetBSD the size is
>> always being compared to 3, the size of the test 'hidden' file. But I have
>> no idea why...
>>
>> On Fri, Sep 29, 2017 at 12:17 PM Jan Schaumann <jschauma at stevens.edu>
>> wrote:
>>
>>> Jason Ajmo <jajmo at stevens.edu> wrote:
>>> > Code: https://gist.github.com/jajmo/5e4e7827fd5b52549132a6a6364c4e53
>>> > The following are sorted based on filesize, descending (ls -lS)
>>> > On Linux, the objects are linked with -lbsd, and include bsd/bsd.h.
>>> >
>>> > Output on Unix:
>>>
>>> I think you mean 'NetBSD', which is a Unix-like OS.
>>> https://en.wikipedia.org/wiki/Unix-like
>>>
>>> > [vagrant at vagrant midterm]$ ./ls -lS
>>> > total 216
>>> > -rw-r--r--  1 vagrant 1000  1846 Sep 28 16:29 helpers.c
>>> > -rw-r--r--  1 vagrant 1000  3376 Sep 29 15:59 sort.o
>>>
>>> Weird.  Looks like no sorting is taking place at all.  Have you
>>> confirmed that the code block you think is being executed is in fact
>>> being executed?
>>>
>>> -Jan
>>> _______________________________________________
>>> cs631apue mailing list
>>> cs631apue at lists.stevens.edu
>>> https://lists.stevens.edu/mailman/listinfo/cs631apue
>>>
>> --
>> Jason Ajmo
>> Stevens Institute of Technology
>> B.S. Cybersecurity '17
>> M.S. Computer Science '18
>> 0x56FA3123
>>
> --
> Jason Ajmo
> Stevens Institute of Technology
> B.S. Cybersecurity '17
> M.S. Computer Science '18
> 0x56FA3123
>
-- 
Jason Ajmo
Stevens Institute of Technology
B.S. Cybersecurity '17
M.S. Computer Science '18
0x56FA3123
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20170929/51a719cd/attachment-0001.html>


More information about the cs631apue mailing list