unix

How to create a pseudo-tty for reading output and writing to input

I am using fork() and execvp() to spawn a process that must believe it is connected to an interactive terminal for it to function properly. Once spawned, I want to capture all the output from the process, as well as be able to send input to the process. I suspect psuedo-ttys may help here. Does anyone have a snippet on how to do this?...

find-command: search with created time

How can I find things created "Jul 30 04:37" and move them to /tmp? Something wrong: find . -ctime "0037043007" -exec mv {} /tmp + ...

Easiest Way to Generate Unix timestamp?

Related question is "Datetime To Unix timestamp", but this question is more general. I need Unix timestamps to solve my last question. My interests are Python, Ruby and Haskell, but other approaches are welcome. What is the easiest way to generate Unix timestamps? ...

To change $USER in OS X's terminal

I would like an other way to change my current user than by GUI. It would be great that if you can change the user as fast as you can your login shell by chsh. How can you change the user in OS X's terminal? ...

How to use VIM to remember open files between sessions?

I use VIM as my main text editor here at work and I often have 10-15 files open at once in a couple of windows with several tabs, each of which has its own split windows. I love using VIM, but I hate having to re-do my entire set-up every time the dev server gets bounced or my machine crashes. Is there a way to get VIM to remember a setu...

Multithreading - Synchronization on Unix

Hi, I am facing sync related issue in multi threading. I have an shared library which applications use to build there applications. From the library I have created a thread which listen to the request coming and process it its is real time thread.From the library i have invoked an API which is sync in nature which will wait for response ...

SQL to compare two unix timestamps?

Hi, I have a table with a field that contains unix timestamps for each record. I would like to return each row where the year and month are equal to the current year and month. Is there a simple way to do this? Thanks ...

Why do some compilers use "a.out" as the default name for executables?

Most UNIX C compilers link executables by default to a file called "a.out". Why? Is this a written standard or just de-facto standard behavior? What would break if these compilers would just produce an error message (or use a different default name) instead of producing "a.out"? ...

Capture unix output using C#

We have soap services running on our unix box (local network with AFS). Sometimes our services are down and our front end developers, due to lack of knowledge of unix find it difficult to restart the services. Is it possible to build a UI(C#-winforms) which will login to the Unix box and run scripts which starts the service/runs a comman...

Dumping dataset (.ds) file contents to a text file

At work we use DataStage which uses dataset (.ds) files. I can view the contents of the file from without our UNIX environment by using: orchadmin dump -name <dataset name> This only dumps the contents of the file to the screen. What I would like to do is have that dump stored inside a text file which I could then open/read from withi...

C++ Timers in Unix

We have an API that handles event timers. This API says that it uses OS callbacks to handle timed events (using select(), apparently). The api claims this order of execution as well: readable events writable events timer events This works by creating a point to a Timer object, but passing the create function a function callback: Some...

Most Compact Way to Count Number of Lines in a File in C++

What's the most compact way to compute the number of lines of a file? I need this information to create/initialize a matrix data structure. Later I have to go through the file again and store the information inside a matrix. Update: Based on Dave Gamble's. But why this doesn't compile? Note that the file could be very large. So I try t...

Parsing line continuations

What is the simplest way to parse line continuation characters? This seems like such a basic action that I'm surprised there's no basic command for doing this. 'while read' and 'while read -r' loops don't do what I want, and the easiest solution I've found is the sed solution below. Is there a way to do this with something basic like ...

Difference between ByteBuffer.allocateDirect() and MappedByteBuffer.load()

Hi , I was trying to implement a sort of shared cache between two or more JVMs by memory mapping a particular file using MappedByteBuffer. From the specifications I see that when we use MappedByteBuffer.load() it should load the data into a direct buffer. I have a couple of questions on this. My code snippet:: RandomAccessFile file =...

How do I insert a line at a specific row in multiple files on Unix?

I need to insert a line with specific text on the second line (thus moving the other lines down in the file) of hundreds of files in a directory. Any quick Unix tips on how that can be done? ...

Is there a Perl module that works similarly to the Unix "which" command?

I was on Perlmonks and found this great listing: http://www.perlmonks.org/?node_id=627015 But it was missing "which", the function that searches for an executable in all the directories in your PATH. (I am porting a Perl script to Windows.) Is there a Perl module that simulates this? ...

What is the simplest way to SSH using Python?

What is the absolute simplest way to SSH to a remote server from a local Python (3.0) script, supply a login/password, execute a command and print the output to the the Python console? I would rather not use any large external library and not install anything on the remote server. ...

How Operating System callbacks work.

Follow up question to: This question As described in the linked question, we have an API that uses an event look that polls select() to handle user defined callbacks. I have a class using this like such: class example{ public: example(){ Timer* theTimer1 = Timer::Event::create(timeInterval,&example::FunctionName); ...

How do I create a link to open an ssh connection

I am trying to create a link to open an ssh connection to another computer. I am an OS X 10.5.7 and Ubuntu 9.04 user. I am tempted to create a symbolic link as such: ln -s "ssh user@computer_name" computer_name I know this is wrong. Could someone point me in the right direction? ...

Memory usage when files are loaded via mmap()

Hi, Wanted to know what if there is a relationship between the maximum amount of memory that can be used to map a file through mmap() and the size of the RAM in a linux box. I tried to memory map some files , and I found that I am not able to map any more files when the "Mapped" usage comes close to the "MemTotal" ( viewed via cat /proc...