Can someone tell me what happens if one uses 'NULL' instead of NULL or (char *)0 in that last exec argument? My guess is that is a signpost for exec to stop collecting arguments. And if it doesn't see it, it continues collecting arguments? Till when?
@FaheemMitha no, there isn’t, since the argument separation is done by constructing the arguments to exec(). You might feel more comfortable using system() instead — that delegates everything to the shell, so you get redirection etc. as well.
@StephenKitt Um, yes. But I thought that maybe those "real" arguments would satisfy some criterion that garbage would not. Like laid out in a certain way.
I don't have a problem with how exec works. Just trying to understand what it does.
And I realise that C by its nature doesn't have a lot of safety built in, and that's OK too.
@FaheemMitha they’re not laid out, the arguments themselves are all pointers — execlp() just sees a succession of pointers on the stack (or whatever the ABI uses to pass pointer arguments), and processes them until it finds a null pointer.
The reason you have to cast is that the default interpretation of 0 is an int, which may not be the same size as a pointer. Due to how C variadic functions work the compiler doesn't know it's meant to be a pointer and can't widen itself. Inside the function, when it looks for a pointer on the stack, it gets mixed garbage instead of something it recognises as null (there are also other reasons, but this one is easy to imagine - 64-bit pointers, 32-bit ints gives half a zero and half detritus)
In reality, 0-without-cast will often work and you don't notice until your code fails on another machine
@FaheemMitha you only segfault if you try to access (maybe even just try to write) memory not belonging to your process. With larger programs it's easy to get (un)lucky and silently corrupt your own memory. As far as I understand.
I have an enough old remote server that lacks many updates for various important programs such gcc and glibc, rubby ,.. etc how can I create an env that enables to get recent updates without root rights?
Or it's impossible one should look into another radical solution?
In practice, as you say, it's possible to do quite a lot of reading, and never have a segfault. Though valgrind and friends will tell you about it if you ask.
@StephenKitt As normal with those things, I don't understand what that page is saying. So it sounds like it is safer to go with (char *)0, though it practice NULL will likely be understood to be a null pointer.
@FaheemMitha the process needs to remember what memory it has allocated
but the stack is somewhat special
@FaheemMitha it’s the clearest IMO — the language guarantees that 0 cast to a pointer is also correct, regardless of the underlying representation. In my mind safety includes both the compiler’s interpretation and humans’ interpretation(s).
I once purchased the "Harbison and Steele" C reference manual, but have rarely looked at it. Maybe once in a while. It's still somewhere in my bookcases.
@StephenKitt I didn't realise the memory was managed by hardware. I thought the kernel (i.e. software) kept tabs. How does the hardware know about processes, anyway?
That was rhetorical. I'm sure the answer is complicated.
@FaheemMitha that’s the distinction in my comment above. The kernel keeps tabs, and knows about all the rules, which is why it’s the judiciary; it configures the MMU to apply the relevant limits, which is why the MMU is the police. When a process accesses memory it shouldn’t, the MMU reacts to the violation and asks the kernel what to do.
I thought improper shutdown could damage files, and maybe more checking and repairing on restarting could damage hdd. The temperature of the hdd was often 50 celcius degree and I left it running for days, weeks, ..., because it couldnt wake up from suspension probably due to outdated Ubuntu and packages.
@Ben Modern filesystems are good at handling such things. I use ext4 and my machine regularly crashes, I'm sorry to say. I've never noticed any corruption.
There might be better choices for FSs. I've heard good things about ZFS. But it's not part of the main kernel, and there are some license issues.
But I don't know if ZFS is actually better than ext4.
The repetitive task is to run on bash ./bashscript inputfile bashscript as the name suggests uses bash shell to execute the program through piping the inputfile to the main executable program which requires the remote machine to compute some data
not lot of coding needed here.
I don't know how such calling the remote executable from VS client side enables to retrieve the desired data from the remote machine
Once upon a time I think Python's os had popen3, which still lives on in other things with similar names. But that function seems to be have been obsoleted by the subprocess library.
Though I don't understand why it was necessary to remove it.
I had to add posix.close(r) and posix.close(e) after the loops to drain them in ps.pipe_simple(). Otherwise got 'too many open files' after 500 calls to this on linux. — robmApr 5 '17 at 7:32
The Valgrind documentation suggests that it reports leaked file descriptors.
The most popular Linux distribution is probably Ubuntu, in life and work, right? I guess that my procrastination of updating and upgrading the system and packages caused my system crashes and my hdd failure.
So I had been thinking about Debian as a better replacement of Ubuntu.
@StephenKitt @FaheemMitha NULL could also just be defined as a raw zero, which would be an int. It'd work as a null pointer in any context where the compiler knows it's supposed to be a pointer, but like Michael said, since execl*() are varargs functions, it can't know that. So we get the issue where execl(..., NULL) could be the same as execl(..., 0), which could cause an issue when the caller passes an int and the function expects a pointer. Hence the cast in this particular case.
There's no such thing as best. I don't know of any "bad" distributions unless you take into account silly things like Suicide Linux or Hannah Montana Linux.
So "best" simply means "this is the one I, personally, enjoy using".
I agree 100%. For most users the best distribution is the one that they are familiar with, or if they’re not particularly familiar with one, the one with which they can easily get help.
Ditto; if I was starting over, I'd look for one that was (1) well-maintained (had a history of regular updates), and (2) made sense to me from system administration & maintenance standpoint
...and I am afraid there is no distribution that can be called "best" when the requirement is not to need (somewhat timely) updates (especially from the security perspective). There are, though, some that tend to perform terribly in that case - e.g. rolling release distributions.
@StephenKitt Yes, and I agree it's an important thing to mention. I was implying that setting up automatic updates is a way of... addressing the need for updating :-) (contrasted to being unwilling to address the issue at all).
@terdon I don't think that's bad too. But it is hard (or impossible?) to support upgrading from an arbitrary point in time. It's reasonable to expect (and is also what I have experienced) that recovering a significantly outdated system would require a significant level of expertise.
@StephenKitt Right. It takes (and took me, for one) some time to get accustomed to the elements (maintainers, repositories, package management, task scheduling...) that make the concept feel natural.
@Ben Ubuntu is probably among the easiest things to just start up and get running.
And it has a huge user community. It even has a separate site on SE.
At least some of time I got the feeling that the people behind the project were trying to position it as a competitor to MS Windows. Not direct competition, perhaps. More something people fed up with MS Win could relatively easily transition to.
But I haven't made any effort to track the project in a long time.
This isn't a recommendation so much as an observation.
@FaheemMitha It's chat, there are no clear "on topic" or "off topic" things. But you basically seem to be talking to yourself about a post on another site using a language most of the people here have no experience with (lua). Surely it would be more helpful for you to discuss this in a place where programmers hang out.
In any case, asking why someone's code didn't close a file descriptor sounds like something you should be asking the poster, or posting a question on SO about.
@terdon I'm not "talking to myself". I've been discussing this with people in the chat sporadically over the last couple of days. And Lua Posix calls are just a thin wrapper for the corresponding C system calls. The conversation is mostly about the Posix calls. Lua is an unimportant detail. I'm just referencing the post because it's close to something I'm trying to do.
There might be better matches out there, but I haven't found one, and it's probably worth doing a lot of searching, because the basic structure is quite simple.
Without the _exit(EXIT_FAILURE); line, the child exit code returns 0. I'm guessing that is what it was initialized as. With that line, it returns the correct exit code.
I'm guessing that the exit is required for waitpid to be properly initialized, but I'm not completely clear why.
Correction: what waitpid does isn't strictly relevant.
@MichaelHomer Yes, I read that. Didn't understand it, though. So with the call to _exit, the process exit code becomes that corresponding to that execlp call, but not otherwise?
I was wondering what hdd might be cheap and reliable for mirroring my failed 1TB hdd? Anyone can link me to some product webpages on ebay, or other frugal websites?
Might data recovery service want me to send them my data in a hdd? Then do I need two hdds, one for them and one for my future backup?
Is there some website for buying second handed and maybe unused hardware?
Which way shall I go? First dd my 1TB failed hdd to a 1TB .iso file, and then run some forensics tool on the .iso file. What capacity of another hdd do I need for creating a .iso mirror file? Or like what @StephenKitt wrote, directly run ddrescue on the failed hdd, and it will generate lots of logs when mirroring the failed hdd, so I need another 2TB hdd.
@FaheemMitha when I looked at that program (just now, about 45 mins later than the link), I saw the line execlp("lsx", "lsx", "-la", "zarko.tex", (char *)NULL);. Do you have a program called lsx, then? What does it do?
@FaheemMitha, I might suggest getting rid of the pipeworks messing with stderr, and then checking the return value of the execlp() call, and errno after it
@ilkkachu No, it isn't, because void * is not compatible with function pointers
(in the specification, rather than in practice)
On probably-most systems all pointers are the same size and compilers allow it, but in language-lawyer terms you can't cast between function pointers and other pointers
That's what it means by "implementation-defined constant" - your implementation will provide something, but 0 as a pointer type is always a correct null in any C
@Ben As previously said: 1) do nothing with your failed HDD if you are going to hand it to someone else for attempting data recovery; 2) using dd on your failed HDD is unlikely to work, and chances are it will make things worse (depending on how/why the disk is failing); using a data recovery tool to copy the content of your failing HDD to a bigger one seems the only sensible option (unless you are doing (1)).
Thanks. > using a data recovery tool to copy the content of your failing HDD to a bigger one seems the only sensible option What data recovery tool do you know is good/best? With such a tool, will it generate bit-level or file-level results? (like dd or like resync)?
Thanks. I will look into ddrescue. I didn't know the other. If any other data recovery tool, I'd appreciate letting me know.
I am not sure what a data recovery service can do. Can they be more powerful than ddrescue? I also appreciate letting me know any capable data recovery service
What does "reading it live" mean? What is it opposed to?
"disk imaging hardware" does mirroring only creating a copy of the failed hdd?, and then some other tool does analysis and recovery on the copy of the failed hdd?
"reading it live" means performing analysis and recovery on the failed hdd directly?
which may further damage the failed hdd?
Does ddrescue read it live?
@Kusalananda I just learned it on meta. Life is so fragile. Will continue to remember the fun time
and his helps
He often tried to help those being marginalized in the community.