Sat Jul 11 03:43:14 2020
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2015-03-01

LEARN

2020-07-11 | 2020-06-11 | 2020-05-11 | 2020-04-11 | 2020-03-11 | 2020-02-11 | 2020-01-11 | 2019-12-11 | 2019-11-11 | 2019-10-11 | 2019-09-11 | 2019-08-11 | 2019-07-11 | 2019-06-11 | 2019-05-11 | 2019-04-11 | 2019-03-11 | 2019-02-11 | 2019-01-11 | 2018-12-11 | 2018-11-11 | 2018-10-11 | 2018-09-11 | 2018-08-11 | 2018-07-11 | 2018-06-11 | 2018-05-11 | 2018-04-11 | 2018-03-11 | 2018-02-11 | 2018-01-11 | 2017-12-11 | 2017-11-11 | 2017-10-11 | 2017-09-11 | 2017-08-11 | 2017-07-11 | 2017-06-11 | 2017-05-11 | 2017-04-11 | 2017-03-11 | 2017-02-11 | 2017-01-11 | 2016-12-11 | 2016-11-11 | 2016-10-11 | 2016-09-11 | 2016-08-11 | 2016-07-11 | 2016-06-11 | 2016-05-11 | 2016-04-11 | 2016-03-11 | 2016-02-11 | 2016-01-11 | 2015-12-11 | 2015-11-11 | 2015-10-11 | 2015-09-11 | 2015-08-11 | 2015-07-11 | 2015-06-11 | 2015-05-11 | 2015-04-11 | 2015-03-11 | 2015-02-11 | 2015-01-11 | 2014-12-11 | 2014-11-11 | 2014-10-11

Key: archive_learn Value: 2015-03-01

Key: id Value: 543033

MESSAGE
DATE 2015-03-08
FROM Ruben Safir
SUBJECT Subject: [LIU Comp Sci] Re: Operating systems HW
From owner-learn-outgoing-at-mrbrklyn.com Sun Mar 8 20:24:50 2015
Return-Path:
X-Original-To: archive-at-mrbrklyn.com
Delivered-To: archive-at-mrbrklyn.com
Received: by mrbrklyn.com (Postfix)
id 8C914161190; Sun, 8 Mar 2015 20:24:50 -0400 (EDT)
Delivered-To: learn-outgoing-at-mrbrklyn.com
Received: by mrbrklyn.com (Postfix, from userid 28)
id 74426161305; Sun, 8 Mar 2015 20:24:50 -0400 (EDT)
Delivered-To: learn-at-nylxs.com
Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89])
by mrbrklyn.com (Postfix) with ESMTP id A1742161190
for ; Sun, 8 Mar 2015 20:24:49 -0400 (EDT)
Received: from [10.0.0.19] (unknown [96.57.23.82])
by mailbackend.panix.com (Postfix) with ESMTPSA id 8897411ECB;
Sun, 8 Mar 2015 20:24:49 -0400 (EDT)
Message-ID: <54FCE851.70001-at-panix.com>
Date: Sun, 08 Mar 2015 20:24:49 -0400
From: Ruben Safir
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
MIME-Version: 1.0
To: mohammed Ghriga
Subject: [LIU Comp Sci] Re: Operating systems HW
References: <54FCE7DB.3000700-at-panix.com>
In-Reply-To: <54FCE7DB.3000700-at-panix.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Sender: owner-learn-at-mrbrklyn.com
Precedence: bulk
Reply-To: learn-at-mrbrklyn.com

BTW this was the question:
Programming Problems
2.26
In Section 2.3, we described a program that copies the contents of one file
to a destination file. This program works by first prompting the user for
the name of the source and destination files. Write this program using
either the Windows or POSIX API . Be sure to include all necessary error
checking, including ensuring that the source file exists.
Once you have correctly designed and tested the program, if you
used a system that supports it, run the program using a utility that traces
system calls. Linux systems provide the strace utility, and Solaris and
Mac OS X systems use the dtrace command. As Windows systems do
not provide such features, you will have to trace through the Windows
version of this program using a debugger.

One thing you notice is that the GNU optimizer is SMARTER than the C
strings library.


On 03/08/2015 08:22 PM, Ruben Safir wrote:
> I lost track of what the home work was, but before I moved forward
> answering quiz questions, I wanted to tackle some of the coding
> assignments in Chapter 2, because I thought I could learn a lot more
> from them. So I did read Cpt 2 and 3, but I wanted to finish this which
> was good because I completely forgot a number of things about fstat,
> fopen and the use of strace, I had never done that before actually
> although I am familiar and used extensively nm. I made a lot of
> blunders on the way to finishing this, but others might benefit from
> this as well. I'm going on to doing the kernel programming tonight, I
> hope and tackle chapter 3 'quiz' questions at school in the AM before class.
>
> Ruben
>
> #include
> #include
> #include
> #include
> #include
>
> char buf[500] = {0};
> char buf2[500] = {0};
> char * buf3;
> int fd, ret;
> size_t len;
> const char * PASSWD = "/etc/passwd";
> off_t tmpsize;
>
> struct stat filetmp;
>
> FILE * INPUT;
> FILE * OUTPUT;
> int main( int argc, char * argv[])
> {
> puts ("Enter a file to copy\n");
> if ( ! fgets( buf, 500, stdin) )
> return EXIT_FAILURE;
> len = strlen(buf);
> buf[len-1] = 0;
>
>
> puts ("Enter the file to copy to\n");
> if ( ! fgets( buf2, 500, stdin) )
> return EXIT_FAILURE;
> len = strlen(buf2);
> buf2[len-1] = 0;
>
> if( access( buf, F_OK|R_OK ) == 0 ) {
> INPUT = fopen( buf, "r");
> if (INPUT == NULL){
> printf("Can't Open %s\n", buf);
> exit(EXIT_FAILURE);
> }
> }else{
> perror("access INPUT file stat");
> exit (EXIT_FAILURE);
> }
> //File Opened for reading
> fd = fileno(INPUT);
> if (fstat(fd, &filetmp ) == -1){
> perror("stat on reading file:");
> exit(EXIT_FAILURE);
> }
> //FILE IS STATTED
> tmpsize = filetmp.st_size;
> if( (buf3 = (char *) malloc( sizeof(int) * tmpsize)) == NULL)
> exit (EXIT_FAILURE);
> ret = fread(buf3, tmpsize, 1, INPUT);
> if( ret != 1){
> fprintf(stderr, "Read not complete: Req ==> %d Rec ==> %zu \n",
> ret, tmpsize);
> exit(EXIT_FAILURE);
> }
>
> OUTPUT = fopen(buf2, "w");
> if(OUTPUT == NULL){
> printf("Can't Open %s\n ", buf2);
> exit(EXIT_FAILURE);
> }
> //File Open for Writing
> ret = fwrite(buf3, tmpsize, 1, OUTPUT);
> if(ret != 1){
> perror("WRITE");
> fprintf(stderr, "WRITE not complete: Req ==> %d Rec ==> %zu\n",
> ret, tmpsize);
> exit(EXIT_FAILURE);
> }
> free(buf3);
> fclose(INPUT);
> fclose(OUTPUT);
> return 1;
> }
>
> execve("./a.out", ["./a.out"], [/* 55 vars */]) = 0
> brk(0) = 0x68b000
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fdb000
> access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or
> directory)
> open("/home/ruben/GNUstep/Library/Libraries/tls/x86_64/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/home/ruben/GNUstep/Library/Libraries/tls/x86_64", 0x7fffd1634d10)
> = -1 ENOENT (No such file or directory)
> open("/home/ruben/GNUstep/Library/Libraries/tls/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/home/ruben/GNUstep/Library/Libraries/tls", 0x7fffd1634d10) = -1
> ENOENT (No such file or directory)
> open("/home/ruben/GNUstep/Library/Libraries/x86_64/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/home/ruben/GNUstep/Library/Libraries/x86_64", 0x7fffd1634d10) =
> -1 ENOENT (No such file or directory)
> open("/home/ruben/GNUstep/Library/Libraries/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/home/ruben/GNUstep/Library/Libraries", 0x7fffd1634d10) = -1
> ENOENT (No such file or directory)
> open("/root/GNUstep/Library/Libraries/tls/x86_64/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/root/GNUstep/Library/Libraries/tls/x86_64", 0x7fffd1634d10) = -1
> ENOENT (No such file or directory)
> open("/root/GNUstep/Library/Libraries/tls/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/root/GNUstep/Library/Libraries/tls", 0x7fffd1634d10) = -1 ENOENT
> (No such file or directory)
> open("/root/GNUstep/Library/Libraries/x86_64/libc.so.6",
> O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
> stat("/root/GNUstep/Library/Libraries/x86_64", 0x7fffd1634d10) = -1
> ENOENT (No such file or directory)
> open("/root/GNUstep/Library/Libraries/libc.so.6", O_RDONLY|O_CLOEXEC) =
> -1 ENOENT (No such file or directory)
> stat("/root/GNUstep/Library/Libraries", 0x7fffd1634d10) = -1 ENOENT (No
> such file or directory)
> open("/usr/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT
> (No such file or directory)
> stat("/usr/lib/tls/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or
> directory)
> open("/usr/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such
> file or directory)
> stat("/usr/lib/tls", 0x7fffd1634d10) = -1 ENOENT (No such file or
> directory)
> open("/usr/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No
> such file or directory)
> stat("/usr/lib/x86_64", 0x7fffd1634d10) = -1 ENOENT (No such file or
> directory)
> open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
> read(3,
> "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\1\2\0\0\0\0\0"..., 832)
> = 832
> fstat(3, {st_mode=S_IFREG|0755, st_size=1984416, ...}) = 0
> mmap(NULL, 3813200, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
> 0) = 0x7f71c0a18000
> mprotect(0x7f71c0bb1000, 2097152, PROT_NONE) = 0
> mmap(0x7f71c0db1000, 24576, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x199000) = 0x7f71c0db1000
> mmap(0x7f71c0db7000, 16208, PROT_READ|PROT_WRITE,
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f71c0db7000
> close(3) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fda000
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fd9000
> arch_prctl(ARCH_SET_FS, 0x7f71c0fda700) = 0
> mprotect(0x7f71c0db1000, 16384, PROT_READ) = 0
> mprotect(0x7f71c0fdc000, 4096, PROT_READ) = 0
> fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fd8000
> write(1, "Enter a file to copy\n", 21) = 21
> write(1, "\n", 1) = 1
> fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fd7000
> read(0, "/etc/passwd\n", 1024) = 12
> write(1, "Enter the file to copy to\n", 26) = 26
> write(1, "\n", 1) = 1
> read(0, "/home/ruben/ssadsa.tmp\n", 1024) = 23
> access("/etc/passwd", R_OK) = 0
> brk(0) = 0x68b000
> brk(0x6ac000) = 0x6ac000
> open("/etc/passwd", O_RDONLY) = 3
> fstat(3, {st_mode=S_IFREG|0644, st_size=1637, ...}) = 0
> fstat(3, {st_mode=S_IFREG|0644, st_size=1637, ...}) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fd6000
> read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1637
> open("/home/ruben/ssadsa.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 5
> fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
> = 0x7f71c0fd5000
> close(3) = 0
> munmap(0x7f71c0fd6000, 4096) = 0
> write(5, "root:x:0:0:root:/root:/bin/bash\n"..., 1637) = 1637
> close(5) = 0
> munmap(0x7f71c0fd5000, 4096) = 0
> exit_group(1) = ?
> +++ exited with 1 +++
>

  1. 2015-03-01 Ruben <ruben.safir-at-my.liu.edu> Subject: [LIU Comp Sci] Fwd: Re: Linked List Test Question
  2. 2015-03-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] [ruben-at-mrbrklyn.com: fork problem]
  3. 2015-03-03 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Re: fork problem
  4. 2015-03-04 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [LIU Comp Sci] Mid term in Allorithms
  5. 2015-03-04 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] Mid term in Allorithms
  6. 2015-03-04 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [LIU Comp Sci] Mid term in Allorithms
  7. 2015-03-04 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] Mid term in Allorithms
  8. 2015-03-04 Ruben Safir <ruben.safir-at-my.liu.edu> Re: [LIU Comp Sci] Mid term in Allorithms
  9. 2015-03-04 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [LIU Comp Sci] Mid term in Allorithms
  10. 2015-03-04 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Kanpsack problemi
  11. 2015-03-04 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Mid term in Allorithms
  12. 2015-03-05 Kamran <kamran.mirzayev-at-my.liu.edu> Re: [LIU Comp Sci] Canonical's 2015 OpenStack Roadshow
  13. 2015-03-05 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] Canonical's 2015 OpenStack Roadshow
  14. 2015-03-05 Ruben <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Forks - Operating systems class
  15. 2015-03-06 Ruben <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] KDE Mentoring -
  16. 2015-03-06 Ruben <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] networking class
  17. 2015-03-07 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Operating Systems class submition
  18. 2015-03-08 From: "keisha.sylvester" <keisha.sylvester-at-my.liu.edu> RE: [LIU Comp Sci] Operating Systems Supplement Text
  19. 2015-03-08 Ruben <ruben.safir-at-my.liu.edu> Re: [LIU Comp Sci] Operating Systems Supplement Text
  20. 2015-03-08 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Operating systems HW
  21. 2015-03-08 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Operating Systems Supplement Text
  22. 2015-03-08 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Re: Operating systems HW
  23. 2015-03-11 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] Operating Systems class submition
  24. 2015-03-11 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] February Journal almost completed
  25. 2015-03-16 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] Operating Systems Chapter 3 HW complete
  26. 2015-03-16 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [ruben-at-mrbrklyn.com: os hw]
  27. 2015-03-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: NYC local: UNIGROUP 19-MAR-2015 (Thu): Penguin Computing presents
  28. 2015-03-19 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] LIU Center for Entrepreneurship + Innovation
  29. 2015-03-20 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Optimum
  30. 2015-03-20 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [jkeen-at-verizon.net: 2nd New York City Perl Hackathon: hold the
  31. 2015-03-22 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Re: Kernel thread scheduling
  32. 2015-03-22 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [jkeen-at-verizon.net: New York City Perl Hackathon 2015: Registration
  33. 2015-03-22 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [vinc94-at-gmail.com: Re: Kernel thread scheduling]
  34. 2015-03-22 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [xerofoify-at-gmail.com: Re: Kernel thread scheduling]
  35. 2015-03-23 Keisha Sylvester <keisha.sylvester-at-my.liu.edu> Re: [LIU Comp Sci] Meeting Announcement II
  36. 2015-03-23 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Meeting Announcement II
  37. 2015-03-23 mrbrklyn-at-panix.com Subject: [LIU Comp Sci] [gabor-at-szabgab.com: [Perlweekly] #191 - Hackathon after Hackathon]
  38. 2015-03-24 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [LIU Comp Sci] GNU/Linux 1
  39. 2015-03-24 Maneesh Kongara <maneeshkongara-at-gmail.com> Re: [LIU Comp Sci] GNU/Linux 1
  40. 2015-03-24 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] GNU/Linux 1
  41. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] GNU/Linux 1
  42. 2015-03-25 Ruben <ruben.safir-at-my.liu.edu> Re: [LIU Comp Sci] GNU/Linux 1
  43. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Re: [LIU Comp Sci] GNU/Linux 1
  44. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] decent threading outline that fills in where our notes let off
  45. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] I love this HW problem
  46. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Java Crimes
  47. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] jobs jobs
  48. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Threaded Programming example
  49. 2015-03-25 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Threads and Speed
  50. 2015-03-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Cpt 4 HW from pr 13-18
  51. 2015-03-26 Ruben <ruben.safir-at-my.liu.edu> Subject: [LIU Comp Sci] Fwd: [NYLXS - HANGOUT] GNU/Linux 1
  52. 2015-03-26 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Kernel Learning Resource - #1
  53. 2015-03-27 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] AVl Trees
  54. 2015-03-27 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Re: Cpt 4 HW Programming Project 4-20 (and 3-20)
  55. 2015-03-28 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Jobs
  56. 2015-03-28 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] JOUNAL MEETING AT 10AM TOMORROW
  57. 2015-03-29 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] Fwd: usage of dma_common_mmap
  58. 2015-03-30 Ruben Safir <mrbrklyn-at-panix.com> Subject: [LIU Comp Sci] HW 4.18 Problem

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!