Unix Programming Questions

0 views
Skip to first unread message

Faustina Bartsch

unread,
Aug 3, 2024, 5:02:01 PM8/3/24
to framlectnewsde

After five years of professional Java (and to a lesser extent, Python) programming and slowly feeling my computer science education slip away, I decided I wanted to broaden my horizons / general usefulness to the world and do something that feels more (to me) like I really have an influence over the machine. I chose to learn C and Unix programming since I feel like that is where many of the most interesting problems are.

My end goal is to be able to do this professionally, if for no other reason than the fact that I have to spend 40-50 hours per week on work that pays the bills, so it may as well also be the type of coding I want to get better at. Of course, you don't get hired to do things you haven't done before, so for now I am ramping up on my own.

To this end, I started with K&R, which was a great resource in part due to the exercises spread throughout each chapter. After that I moved on to Computer Systems: A Programmer's Perspective, followed by ten chapters of Advanced Programming in the Unix Environment. When I am done with this book, I will read Unix Network Programming.

What I'm missing in the Stevens books is the lack of programming problems; they mainly document functionality and provide examples, with a few end-of-chapter questions following. I feel that I would benefit much more from being challenged to use the knowledge in each chapter a la K&R. I could write some test program for each function, but this is a less desirable method as (1) I would probably be less motivated than if I were rising to some external challenge, and (2) I will naturally only think to use the function in the ways that have already occurred to me.

So, I'd like to get some recommendations on how to practice. Obviously, my first choice would be to find some resource that has Unix programming challenges. I have also considered finding and attempting to contribute to some open source C project, but this is a bit daunting as there would be some overhead in learning to use the software, then learning the codebase. The only open-source C project I can think of that I use regularly is Python, and I'm not sure how easy that would be to get started on.

Reinvent a lot of the core Unix utilities. Most of these were (and still are) written in C, so they are a good way to start off learning. Depending on your skill, pick harder or easier utilities to copy.

Google for computer science operating system courses and do the projects there. Many schools have these projects on public websites so you could get everything you need. Here is a link to Purdue's site. Give the shell project a shot; it was difficult, but really educational.

Practice some of the idioms (understand the ins and outs of pointers etc) and pick projects that help with that. The third item in the list has an answer (disclaimer, I wrote it) with a bunch of high-level C idioms where an idiomatic C program would differ from Java.

Learning XLib or Win32 GUI programming with C is probably less useful as almost anything is better than C for GUI programming and wrapping a core C engine with another language is generally much easier - unless you're really concerned with speed. As a starting point, concentrate on 'systems' programming applications, which is where you are most likely to get real mileage from C. Learn how the C interface of one of the scripting languages like Tcl or Python works.

Writing some bit-twiddly and pointer heavy code (e.g. picking apart network packets or interpreting a protocol), or server-side items using sockets will take you right into C's core competencies. If you've got some of the WRS books, try making pthreads work (IIRC UNP2 has a big section about pThreads). For a contrast, write something that uses non-blocking I/O. This stuff is C's home turf and you'll get a good working knowledge of C by doing this. Troll through the RFCs for some ideas of network protocols to implement.

Are you open to book suggestions? Although it is a bit dated (where "a bit" perhaps is a huge understatement), Maurice Bach's "The Design of the Unix Operating System" is a great book. It belongs next to K&R on your bookshelf.

You might try working your way through all the examples in the book Software Tools (Amazon). Much of it is pretty pedestrian (right-justify text, de-tabify, etc.), but it's a great introduction to the Unix philosophy and basic C programming.

This is pretty interesting. As we know that Unix is designed by using the C language, it may not difficult to learn. If you are using the Windows OS, you can use a "Windows services for Unix" application to practice your programs. If you are using Unix, then we can use editors like vi.

Try to test most of the Unix APIs (files, sockets, etc.) to see how they work. You could for example get an Unix programming book, follow its chapters and test on your application everything you read, by creating your own functions. On that way, you can start to develop your own function library to be used in further projects.

"ephemeral port in UNIX" Exactly this question was asked me on one of leading broker firms interview apparently they had some port clashing due to this and there Fixed Income trading system was not responding because of port clash.

Sorry to say but I would much rather get somebody on board who knows how to use info or man pages or google to find the answers to these questions then to know every details about unix commands from their head. Especially when they apply for a java job.

Answer to question about CPU(s) number is wrong, because it will work only in Linux, it doesn't cover other Unices, ie. Solaris doesn't have a /proc/cpuinfo.
"10. How do you find whether your system is 32 bit or 64 bit ?" Again, not all Unices have arch command.
It has to be noted, that most of the answers still are right, however one has to be aware of:
top has been reported to print false values on Solaris, it is better to use prstat. ps behaves differently on Solaris than on Linux and some switches don't work.
Otherwise, bravo. Very nice summary.

@Anonymous2, yeah for Java jobs , Java is more important than Unix but anybody wants to hire someone who is good on all technology which is been using in project but of-course compromise can be made on supporting technology but not on primary.

@Trochej , Thanks for your valuable comment. I haven't worked on Solaris but your points are well valid. I read somewhere that even worse is "killall process-name" command which instead of killing named process kill all process on Solaris.

In one of Unix interview they asked me how to remove Ctrl+M Character, I surprised with this unix interview question, it was more to convert file from dos to unix. would be great if you could provide answer of this unix question.

Intermediate #7: "In a file [the] word UNIX is appearing many times? How will you count [the] number?"

Even with case insensitive "-ci", as someone else suggested, you would still only get a count of the "lines" where the word "unix" appeared, not the "count". If you want to know how many times "UNIX" (any case) actually appears, I would suggest something like this:

$ tr "[:space:][:punct:]" "\n" < filename grep -ci unix

Just saying... good list by the way

Can any one please share UNIX or Linux Interview question for System admin ? I am looking for some real tricky UNIX question which can be testing. Would be great if one can share from IB like Citibank, Barclays, Goldman Sachs, Standarad Charted, Morgan Stanley or RBS.

Senthil

Actually it is quite a good interview question if the person understands the difference between 'top' and 'prstat' commands and why one may become a CPU hog (guess which one). This will give an idea if the person has been exposed to some really, really large OS images .. or have only been exposed to your average single-socket Linux box.

But it depends what type of environment you want him to work in. For most Linux environments you never have to worry about the fact that 'top' has an build-in weakness if there are really MANY processes to iterate over. It is not a problem you're likely to encounter anyways.

In Advanced UNIX Interview Question,
Answer 3: What is nohup?
nohup is a command, which is used to start any service or run any long running command, so that process doesn't die, when user logout from machine. We used to start our Java Services using nohup command so that it keeps running, even after you log out from shell.

Instead of command line trivia I prefer to ask a question that gives an interviewee enough room to maneuver. One with a long enough answer so you can determine if the user understands the entire system and whose response will let you know their level of expertise.

Something like "In as much detail as possible explain what happens when you say ssh hostname". Ideally mentioning shell, searching the path, execing a binary, libraries, page faults, parsing options, dns, netmask, gateway, routing, tcp handshake, ssh negotiation, etc. A good answer will take some time, but you'll learn quite a bit about the interviewee in the process.

here few more questions -
1. How to create file system in UNIX ?
2. Explain LVM and it's use?
3. How to mount and unmount drives ?
4. How to configure a process to start on boot ?
5. How to add / modify users ?
6. How to check mail queue ?
7. Where are system log files located ?

Thanks . It is good article but I checked with RHCE linux this command only showing data replacement .

sed s/Unix/UNIX/g fileName

But once I run the command "sed -i s/Unix/UNIX/g fileName" . It was working .Please correct me if I am going wrong .Thanks in advance.

The given answer for:
7. In a file word UNIX is appearing many times? How will you count number?
wont work in all cases as it counts each line only once even if it contains multiple occurrence of the word.
"grep -o "Unix" wc -l" can be used instead

c80f0f1006
Reply all
Reply to author
Forward
0 new messages