Just out of curiosity: What’s the oldest code/package in a typical linux distro? Emacs? GCC? Answer Sun RPC is pretty old, and it’s in the C library: http://blogs.oracle.com/webmink/entry/old_code_and_old_licenses
Tag: linux
Is it possible to make stdout and stderr output be of different colors in XTerm or Konsole?
Is it even achievable? I would like the output from a command’s stderr to be rendered in a different color than stdout (for example, in red). I need such a modification to work with the Bash shell in the Konsole, XTerm, or GNOME Terminal terminal emulators on Linux. Answer Here’s a solution that combine…
Compress files while reading data from STDIN
Is it possible to compress (create a compressed archive) data while reading from stdin on Linux? Answer Yes, use gzip for this. The best way is to read data as input and redirect the compressed to output file i.e. cat test.csv will send the data as stdout and using pipe-sign gzip will read that data as stdin.…
Non-blocking pipe using popen?
I’d like to open a pipe using popen() and have non-blocking ‘read’ access to it. How can I achieve this? (The examples I found were all blocking/synchronous) Answer Setup like this: Now you can read: When you’re done, cleanup:
Is errno thread-safe?
In errno.h, this variable is declared as extern int errno; so my question is, is it safe to check errno value after some calls or use perror() in multi-threaded code. Is this a thread safe variable? If not, then whats the alternative ? I am using linux with gcc on x86 architecture. Answer Yes, it is thread sa…
How to find directories with the name of specific length
How could I find directories with the name of specific length? For example, I have bunch of directories which have length of the name equal to 33 chars (‘a92e8cc611fdebcca3cf2fc8dc02c918’, ‘c442fb3f46d6c8bd17d27245290a9512’ and so on). Does find utility accepts condition in form of the…
thread level memory consumption of process
How do I get per thread based memory consumption of a process in Linux? I understand that we can use /proc/pid/task/tid/statm, but thats not helping my case. All the threads show same value and its same as PID’s statm. We can do valgrind but I am not looking for any invalid read/write or leaks. Valgrind…
How to eject the CD Drive on Linux using C?
I was reading through this Advanced Linux Programming tutorial when I encountered a problem. I was trying to eject the CD-ROM drive using this code: Then I try to compile this code and get the following output: So what am I doing wrong? Answer The error message you’re seeing looks like something is wron…
How to get the last key pressed without stopping the C program?
Writing an application with command line interface and I would like to know at any time if F1 or ESC or an arrow key is pressed. What is the simplest way of doing this? I would like to avoid using a readline type library. This is a Linux specific question; the program is not multithreaded. Answer An implement…
How do I find the size of mounted USB flash drive in C?
I have a flash drive device (/dev/sda1) mounted to /mnt on an embedded linux system (kernel 2.6.23). Using C how do I work out the size of the drive? Answer On Linux, if you’re not worried about portability (C doesn’t know about drives, so any such specific code will be unportable), use statfs():