Skip to content
Advertisement

naming convention for shell script and makefile

I have a few makefiles that store shared variables, such as CC=gcc , how should I name them? The candidates are: .. which is more classic? Is there a standard? Similarly, I have some shell scripts, which should i choose among the following: Is there a generally accepted ‘case’ and suffix for these? Answer What you’ve got are the bits

Oldest code in a typical Linux distro

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

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. Make sure to

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 safe. On Linux,

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 ‘wc -c’? Or maybe some other utilities should be piped together? Answer few ways with GNU find

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 will not tell me any

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 wrong in your #include lines, not with

Advertisement