unix

Pipe is not receiving all output from child process

I wanted to open up a pipe to a program and read output from it. My initial inclination was to use popen(), but the program takes a number of options, and rather that fighting with shell quoting/escaping, I decided to use a combination of pipe(), fork(), dup() to tie the ends of the pipe to stdin/stdout in the parent/child, and execv() t...

Run php script as daemon process

I need to run a php script as daemon process (wait for instructions and do stuff). cron job will not do it for me because actions need to be taken as soon as instruction arrives. I know PHP is not really the best option for daemon processes due to memory management issues, but due to various reasons I have to use PHP in this case. I came...

How do I change a shell scripts character encoding?

I am using Gina Trapiani's excellent todo.sh to organize my todo-list. However being a dane, it would be nice if the script accepted special danish characters like and . I am an absolute UNIX-n00b, so it would be a great help if anybody could tell me how to fix this! :) ...

How to convert to a zero byte file?

HI, in unix there are number of files in my directory. i want to change all the files to zero byte files. is that possible on a single command line? for example: -rw-r--r-- 1 sumanma dev 434 Jan 8 14:36 pprbc_NL.cpp -rw-r--r-- 1 sumanma dev 488 Jan 8 14:37 pprbc_TreeBuild.cpp -rw-r--r-- 1 sumanma dev ...

Measuring amount of CPU time taken by a piece of code, in C on Unix/Linux.

Hi, Can clock() be used as a dependable API to measure time taken by CPU to execute a snippet of code? When verified usng times() / clock(), both do not seem to measure the CPU time taken precisely. Firstly, can the APIs clock()/times() be used to measure the execution time of a function/snippet of code, as given in the example below?...

How would you do a search from the unix shell with both constraints on the filename and the file content?

Can find perform full-text search? How would you do a search with both some constraints on the filename and the file content? ...

interact (stdin/out) with command line programs at runtime in C

I think the thing I want to do is called GUI/command line wrapping sftp(1). I need an easy way to start that program and react on its output while running. Additionally I have to be able to send input to it, full interaction is required. I tried forkpty (emulated TTY), but there wasn't one good example findable using forkpty for that jo...

How can I get the filesystem page size from unix/linux/osx and windows?

I want to be able to determine at runtime what the sector size is for a give filesystem. C code is acceptable. for example I format my Data partitions with a 32k sector size that have lots of large video files. I want to be able to get this value at runtime. ...

How to run gdb against a daemon in the background?

I'm trying to debug a server I wrote with gdb as it segfaults under very specific and rare conditions. Is there any way I can make gdb run in the background (via quiet or batch mode?), follow children (as my server is a daemon and detaches from the main PID) and automatically dump the core and the backtrace (to a designated file) once ...

How do I free memory obtained by sbrk() ?

I have a custom allocator function which uses sbrk() to obtain memory. How do I release this memory when it's no longer needed? Is there a function equivalent to free() for malloc() ? or do I have to use brk() to set the end of the data segment ? ...

Escaping colons in filenames in a Makefile

Is there a way to get GNU make to work correctly with filenames that contain colons? The specific problem I'm running into happens to involve a pattern rule. Here's a simplified version that does not depend on cutting and pasting tab characters: % make --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is ...

How to disable shell interception of control characters?

Hi. I'm writing a curses application in Python under UNIX. I want to enable the user to use C-Y to yank from a kill ring a la Emacs. The trouble is, of course, that C-Y is caught by my shell which then sends SIGTSTP to my process. In addition, C-Z also results in SIGTSTP being sent, so catching the signal means that C-Y and C-Z are not...

Write my own 'everything is a file' interface

I would like to expose the settings and statistics of my program in a 'everything is a file' manner - sort of how /proc/ and /sys/ works. As an example, imagine for a moment that apache2 had this type of interface. You would then be able to do something like this (hypothetical): cd /apache2/virtual_hosts mkdir 172.20.30.50 cd 172.20.3...

gnu screen: can you automatically name a window after the last invoked program?

Is there a way to automatically have each window change its name to the name of the last program you ran from that window? This would be more convenient than having to rename the windows manually. ...

How to get the width of terminal window in Ruby

Have you ever noticed that if you run rake -T in rails the list of rake descriptions are truncated by the width of the terminal window. So there should be a way to get it in Ruby and Use it. I'm printing some Ascii-art on the screen and I don't want it to be broken. therefore I need to find out the width of terminal at run time some ho...

diff'ing diffs with diff?

I need to know if the two patches are effectively the same. I have an old patch file and new patch file created with the unix diff command. Just diff'ing the patches reports differences due to the timestamp when the patch was created. Is there a way (with diff?) that can reliably tell me if the two patches are effectively the same? ...

Seg fault with open command when trying to open very large file

I'm taking a networking class at school and am using C/GDB for the first time. Our assignment is to make a webserver that communicates with a client browser. I am well underway and can open files and send them to the client. Everything goes great till I open a very large file and then I seg fault. I'm not a pro at C/GDB so I'm sorry if t...

Pipe file disappears but still works

I have 2 programs, both written in Java. The first launches several instances of the second and then communicates with them via pipe files. When running 2 instances of the program, (I'll call the launcher A and the others B and C) everything works fine. The pipe files are in /tmp/[pid of A]/B and /tmp[pid of A]/C. If B or C close then ot...

No username when Oracle Forms calls Solaris shell script

Our application has a couple of shell scripts that are called from web-based Oracle Forms 10g, running on multiple Solaris 10 servers. We've discovered recently that the shell scripts are not running with the full permissions of the OAS user account that runs the forms. I added a echo User is $USER command to one script to display the ...

Pseudo filesystems on *nix

I need some opinions pointers on creating pseudo-filesystems for linux/*nix systems. Firstly when I say pseudo-filesystem I mean something like /proc where the structure within does not represent actual files on disks or such but the state of the kernel. I would like to try something similar as an interface to an application. As an exa...