unix

Catching signal inside its own handler

#include<stdio.h> #include<signal.h> void handler(int signo) { printf("Into handler\n"); while(1); } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(& act.sa_mask); sigaction(SIGINT, &act, NULL); while(1); return 0; } After catching the KeyboardInterrupt on...

What's the single best reference on the topic of (POSIX) signals?

Signals seem to be one of those areas that should be conceptually simple and easy to explain but I have never come across one source that is both comprehensive, lucidly written, and up to date. In part this seems to be because of historical cruft, lots of exceptions to rules, different programming standards, the confusion threads throw ...

Average and maximum size of directories

I have a directory and a bunch of sub-directories like this: - directory1 (sub-dir1, sub-dir2, sub-dir3, sub-dir4, sub-dir5...........and so on, hundreds of them...) How do I find out what is average size of the sub-directories? And how do I find what is the maximum size of the sub-directories? All using Unix commands... Thanks. ...

ATOM date format to UNIX in PHP

So this cant be too difficult, I need a feed date/time converted into a unix timestamp in PHP. from "2010-04-13T10:00:00.000-04:00" -> Unix I have been trying all sorts of weird things with date() and strtotime() with no luck. Thank you! ...

windows equivalent of inet_aton

I'm converting some code written for a linux system to a windows system. I'm using C++ for my windows system and wanted to know the equivalent of the function inet_aton. ...

Log parser/analyzer in Unix

What's the popular tool people use in Unix to parse/analyze log files? Doing counting, find unique, select/copy certain line which have certain patterns. Please advise some tools or some keyword. Since I believe there must be similar questions asked before, but I don't any idea about the keywords. Thanks. ...

How to create threads and sort correctly in a odd-even sorting program?

I am trying to implement the odd-even transposition sorting algorithm in c with multi-threading. The program will receive a file with a line of integers that need to be correctly sorted. I have created the array that the program will work with and I am reading in the data correctly. Although, I am not quite sure how to create the threads...

In my Apache2 access.log, how do I filter what gets displayed?

Someone told me to do this in order to keep track of latest people hitting my server: tail -f access.log However, this shows all the "includes", including the JS file, the graphics, etc. What if I just want to see the pages that people hit? How do I filter that using tail -f? ...

Are there any platforms where using structure copy on an fd_set (for select() or pselect()) causes problems?

The select() and pselect() system calls modify their arguments (the 'fd_set *' arguments), so the input value tells the system which file descriptors to check and the return values tell the programmer which file descriptors are currently usable. If you are going to call them repeatedly for the same set of file descriptors, you need to e...

Understanding the Unix file system and ruby installs without Sudo

I'm trying to comprehend the Unix file system on my OSX. I'm following wikipedia Filesystem Hierarchy Standard. I understand when I install ruby gems I must use the command sudo gem install but if I omit sudo, problems may occur. Where are gems installed within the file system when I omit sudo? How can I delete these gems? A Fun side ...

How to write ONE line of command that scp all the sub-directories in a directory to a remote machine

something like: scp -r all_directories_in_current_directory fenix@xxxxx:~/data anyone can give me a clue? ...

Floating Point Comparison in Shell Script

Hello, Can you please suggest me the syntax for doing floating point comparison in shell script. I am using bash. I would ideally like to use as part of if statement here is a small code snippet : key1="12.3" result="12.2" if (( $result <= $key1 )) then # some code here fi thanks Kiran ...

How do I know if an C program's executable is run in foreground or background ?

In my C program I want to know if my executable is run in foreground like this $./a.out or like this $./a.out & ...

Vim: Custom Folding function done, custom highlighting required

I have defined a function in vim to properly indent folds. Ie so they look like this: Unfolded this is text also text indented text indented text not indented text folded with default function this is text also text +-- 2 lines: indented text ---------------------------- not indented text folded with my new function th...

Grepping for string containing dash

I want to grep for the string "-X" in a file but it's confusing this as a command line argument. I've tried grep "-X" grep \-X grep '-X' ...

Formatting with echo command

The actual situation is a bit complicated, but the issue I'm running into is that I have an echo command within an eval command. Like so: $ eval echo 'keep my spacing' keep my spacing $ echo 'keep my spacing' keep my spacing I was wondering how I could keep eval from stripping my spacing so that the first command pri...

unix cut, remove first token

I'm trying to use unix cut to remove the first two fields per line. I have input lines of of the form (token)(whitespace)(token)(lots of text) The problem is that there exit n tokens per line, so I can't do something like this cut -f3,4,5,6,7,8,9 is there a way to tell cut to take everything except the specified fields ...

find: What's up with basename and dirname?

I'm using find for a task and I noticed that when I do something like this: find `pwd` -name "file.ext" -exec echo $(dirname {}) \; it will give you dots only for each match. When you s/dirname/basename in that command you get the full pathnames. Am I screwing something up here or is this expected behavior? I'm used to basename givin...

Multiple Progress Bar

Hello, In addition to my previous query concerning multi-threading in shell scripting I am curious if its possible to have multiple progress bar. Here is a code snippet of my expected result : Output : 1 of 100 Files Completed # Thread1 Output : 10 of 45 files Completed # Thread 2 The lines are updated showing the progre...

Behavior of a pipe after a fork()

When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that after a fork that the parent can close() the read end of a pipe and it doesn't close the read end for the child. When a process forks, does its file descriptors get retained? What I mean by this is that before the fork the pipe read file descriptor...