unix

How can I run the first process from a list of processes stored in a file and immediately delete the first line as if the file was a queue and I called "pop"?

I'd like to call the first command listed in a simple text file with \n as the separator in a pop-like fashion: Figure 1: cmdqueue.lst : proc_C1 proc_C2 proc_C3 . . Figure 2: Pop the first command via popcmd: proc_A | proc_B | popcmd cmdqueue.lst | proc_D Figure 3: cmdqueue.lst : proc_C2 proc_C3 proc_C4 . . ...

Differences between System V and Posix semaphores.

What are the trade-offs between using a System V and a Posix semaphore? ...

What is the best way to write a wrapper function that runs commands and logs their exit code

I currently use this function to wrap executing commands and logging their execution, and return code, and exiting in case of a non-zero return code. However this is problematic as apparently, it does double interpolation, making commands with single or double quotes in them break the script. Can you recommend a better way? Here's the...

What is the safest way to empty a directory in *nix?

I'm scared that one day, I'm going to put a space or miss out something in the command I currently use: rm -rf ./* Is there a safer way of emptying the current directory's contents? ...

Unix command to find lines common in two files

I'm sure I once found a unix command which could print the common lines from two or more files, does anyone know its name? It was much simpler than diff. ...

Why is "echo foo | read a ; echo $a" not working as expected?

I could replicate the problem with various shells under FreeBSD, GNU/Linux, and Solaris. It had me head-scratching for more than an hour, so I decided to post the question here. ...

Find PID of a Process by Name without Using popen() or system()

I've a process name and I've to send a kill() signal to that process but I need its PID to call kill(). I would only like to use: popen("pidof process_name"); as the last thing. Is there any other way to find out the process' PID? One way I could think of is to send a socket request to that process and ask to its PID. The other way i...

Convert decimal to hexadecimal in UNIX shell script

In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feeding it ASCII representations of numbers. printf? Gross! Using it for now, but what else is available? :) ...

How to do search/replace in a "binary" file from the command line

I have some data files to import into a database with some "unique" delimiters: Field Separator (FS): SOH (ASCII character 1) Record Separator (RS) : STX (ASCII character 2) +’\n’ I'd like to import the files into Postgres using the COPY command but while I can specify a custom field delimiter, it can't handle the record separator. I...

Good Current Systems Programming Books?

This just occurred to me in answering another question. Can anyone recommend any good, current, systems programming books, for really any variant of UNIX? Such a book would teach file and directory structure, fork/exec, pipes, FIFOS, and semaphores. I'd think (looking back on my similar course) that a reasonable final project would be...

Get specific lines from a text file

I am working on a UNIX box, and trying to run an application, which gives some debug logs to the standard output. I have redirected this output to a log file, but now wish to get the lines where the error is being shown. My problem here is that a simple cat output.log | grep FAIL does not help out. As this shows only the lines which ...

A program to kill long-running runaway programs

I manage Unix systems where, sometimes, programs like CGI scripts run forever, sometimes eating a lot of CPU time and wasting resources. I want a program (typically invoked from cron) which can kill these runaways, based on the following criteria (combined with AND and OR): Name (given by a regexp) CPU time used elapsed time (for pro...

When I run "who am i" at a UNIX prompt, what does "tty" and "ttys" stand for?

I know this is a simple question, I'm just curious. ...

What does the $SHELL command do besides output the shell when I type it at the command prompt?

I know this is supposed to output what kind of shell I'm using, which I think it does, because it outputs "bash-3.2", but it doesn't quite do that, because it actually changes my prompt to "bash-3.2$". What else is going on? When I do Ctrl+D, I go back to my original prompt. Is this starting the bash shell? I thought by opening a ter...

Are there good reasons not to exploit '#!/bin/make -f' at the top of a makefile to give an executable makefile?

Mostly for my amusement, I created a makefile in my $HOME/bin directory called rebuild.mk, and made it executable, and the first lines of the file read: #!/bin/make -f # # Comments on what the makefile is for ... all: ${SCRIPTS} ${LINKS} ... ... I can now type: rebuild.mk and this causes make to execute. What are the reasons fo...

Include softlinked folders in unix "find"

How can I tell unix "find" to include in it's recursive search a folder which is softlinked? ...

Spinning Background Tasks in Rails

What is the preferred way to create a background task for a Rails application? I've heard of Starling/Workling and the good ol' script/runner, but I am curious which is becoming the defacto way to manage this need? Thanks! Clarification: I like the idea of Rake in Background, but the problem is, I need something that is running constan...

Setting up a Mac for programmers

I recently switched over to a MacBook Pro so I'm still really new at Mac software ecosystem. What is the best guide or what tips do you have to quickly get adept at using Mac for developing on both Mac/Unix and MS platforms (*.NET, SharePoint, SQL Server, etc) using VMWare Fusion? For example, I've setup NetBeans, FlexBuilder, Eclipse, T...

Size of a tcp packet on BSD

If i need to find out the size of a tcp packet on BSD.....what do we need to do? Is there some utility which allows for this? ...

What do the values in tload mean?

The server I'm trying to maintain is sassing me. Among other things, I ran tload. This probably provides helpful information to someone who knows how to read this data. I do not. It says: 1.36, 1.12, 0.59 ------------- What should I glean from this? This is our home-grown stat server, it gets a crap-ton of requests, and runs logr...