posborne / linux-programming-interface-exercises Goto Github PK
View Code? Open in Web Editor NEWMy solutions to The Linux Programming Interface Exercises
License: MIT License
My solutions to The Linux Programming Interface Exercises
License: MIT License
Hi there,
I'm learning from TLPI at the moment and in chapter 4. I was doing the cp
exercise and I'm somewhat stuck. I saw your solution and implement it. However, the output isn't any different from the actual copy.c
fiile. In both cases, the files are copying the holes. Also, in your code, you have the following line as well: while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0)
, which says that the loop will continue unless there is an EOF
- similar to the actual copy.c
file as well. Can you tell me how your version of cp.c
is any different from copy.c
given that it is giving me identical output? The file I'm referring to is this one.
Thanks.
Hi!
I want before login with "rc.local" the command /bin/chattr +i or /bin/chattr +a /path/to/file
"rc.local"
#!/bin/sh
mount -t ramfs -o rw,size=1024M ramfs /path/to/folder
/bin/sleep 4
/bin/tar xvzf /path/to/file.tar.gz -C /path/to/folder
/bin/sleep 4
/bin/chattr +a /path/to/file
/bin/sleep 2
exit 0
chattr +a don't set the +a attribute. chattr can't set the attribute of the file, because
error message says the file is not there, but the file is there.
When I set it manually, then it works.
What's wrong?
I find it better to use code like this
write(outputFd, buf, numRead);
'dup2' should not check the validation of 'newfd'.
close it directly and sliently.
Hello, your ideas have impressed and helped me a lot. Thanks!
Exercise 9-5 answer may have a mistake.
// setuid()
/* suspend not possible */
/* resume not possible */
setuid(getuid()); /* Permanently drop privileges*/
Hi, I have a few quick questions about your implementation for this exercise.
For your implementation of setenv
:
I think that the function as written currently could potentially cause a memory leak and/or shrink the existing environment list. If an environment variable is already defined in the list, and it's found as you iterate through the list, the new value for the environment variable is set appropriately (assuming overwrite != 0
). When this happens, isn't there a memory leak that occurs? The memory allocated to store the old value of the environment variable isn't freed, but the pointed to C-string changes. And if this occurs in the middle of the list, the list seems to be truncated (the next element in the list is set to NULL
, which denotes the end of the list). Is this intentional?
For your implementation of unsetenv
:
I think that the same memory leak concern applies here as well.
Also, in my copy of the book, this exercise includes the following:
Your version of unsetenv() should check to see
whether there are multiple definitions of an environment variable, and remove
them all (which is what the glibc version of unsetenv() does).
But I think the current implementation will only remove one (the first) instance of the environment variable.
The original question is wrong, cite errata, page 210
In the second sentence of exercise 1, change:
Assuming that the clock_t value returned by times() is an unsigned 32-bit integer
to:
Assuming that the clock_t value returned by times() is a signed 32-bit integer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.