unix

Why isn't the process I start with Perl's system() a child process?

Perl's system() starts a process, but breaks the parent/child relationship? test.pl: use POSIX; system("./test.sh &"); my $pid = `ps -C test.sh -o pid=`; print "pid: -$pid-\n"; waitpid($pid, 0); test.sh: while true do sleep 1 done When I run test.pl, it finds and prints a correct pid of test.sh. But waitpid() returns -1 an...

How do I get a thread ID from an arbitrary pthread_t?

I have a pthread_t, and I'd like to change its CPU affinity. The problem is that I'm using glibc 2.3.2, which doesn't have pthread_setaffinity_np(). That's OK, though, because pthread_setaffinity_np() is itself a wrapper of sched_setaffinity(), which can be called by passing a thread ID instead of a process ID to set the affinity for an ...

Unix Command For Benchmarking Code Running K times

Hi, Suppose I have a code executed in Unix this way: $ ./mycode My question is is there a way I can time the running time of my code executed K times. The value of K = 1000 for example. I am aware of Unix "time" command, but that only executed 1 instance. ...

Difference between running internal and external unix commands in java

Why can't internal unix commands (cd, pwd, etc) be run directly in java like external commands (chmod, chown, etc) using Runtime.getRuntime().exec() ? Please help with explanation. ...

Inheriting aliases inside UNIX /usr/bin/script

The UNIX "/usr/bin/script" command will create a running transcript of your shell session (see "man script" for more info). However, when inside a script instance, it seems to forget the parent shell's env vars, aliases, etc. The following example demonstrates how the "ll" alias I define is ignored inside "script": zsh> mkdir temp zsh...

Can someone explain this definition of the 'dirent' struct in Solaris?

Recently I was looking at the 'dirent' structure (in dirent.h) and was a little puzzled by its definition. NOTE: This header file is from a Solaris machine at my school. typedef struct dirent { ino_t d_ino; off_t d_off; unsigned short d_reclen; char d_name[1]; } dirent_t; Particularly the d_name field. How would t...

What UNIX commands support coloured output?

I enjoy using UNIX/bash commands that support coloured output. Consequently, I have a few aliases defined which automatically enable coloured output of the commands that I know support this option. However, I'm sure there are hundreds of commands out there that support coloured output - I'd like to know what they are. The ones in my ~...

Substract between columns and print it with AWK

Hi, I have a following input data: AATGCCACGTTGAGAGGCGTTCGCGGAAGGCGCG 44 40.000 AATGCCACTCGGGTCCGAGATGGCGGATCTCCAC 35 37.000 AATGCCAGAGCTGTGGTAGTGTGAAAGCAGCAGT 13 13.000 What I want to do is to substract column 3 by column 2 yielding: AATGCCACGTTGAGAGGCGTTCGCGGAAGGCGCG -4 AATGCCACTCGGGTCCGAGATGGCG...

How to make a non-blocking pipe from the command-line in Solaris?

I'm trying to write a lua script that reads input from other processes and analyzes it. For this purpose I'm using io.popen and it works as expected in Windows, but on Unix(Solaris) reading from io.popen blocks, so the script just waits there until something comes along instead of returning immediately... As far as I know I can't change...

How does commands-piping work in *NIX?

When I do this: find . -name "pattern" | grep "another-pattern" Are the processes, find and grep, spawned together? My guess is yes. If so, then how does this work?: yes | command_that_prompts_for_confirmations If yes is continuously sending 'y' to stdout and command_that_prompts_for_confirmations reads 'y' whenever it's reading it...

Simple Makefile Problem (with a simple dependency)

Hi all, I have 4 '.cpp' files and 1 header files: Tools.cpp Code1.cpp Code2.cpp Code3.cpp and Tools.hh Now all Code1.cpp, Code2.cpp, Code3.cpp use functions stored in Tools.cpp. Currently, what I do to compile all of them is using this simple shell script: #!/bin/bash echo "compiling Code1.cpp"; g++ Code1.cpp Tools.cpp -o Code1 e...

What's your favorite g++ option?

Hi, I am a newbie in C++ programming. When compiling I never use any option. This is my day to day command: g++ MyCode.cc -o MyCode For safety practice what's the best option to use? ...

How can I script copying files from Unix to Windows?

Is there any way a script can be made that copies files from a Unix drive onto a Windows drive? ...

Command line GUID for Unix and Windows?

Is there a command line tool for unix and windows that uses the same algorithm to create GUIDs for both platforms? ...

Howto create software package in Unix/Linux

Hi all, How can we create a software package. So that after extracting our software tar ball user can do the typical steps: $ gunzip < mycode.tar.gz | tar xvf - $ ./configure $ make $ make install ...

Changing Editor for Unix INFO Command

Currently my "info" command uses Emacs as its default editor. $ info printf Is there a way to change it into Vi/Vim? ...

PowerShell vs. Unix Shells

I'm debating whether I should learn PowerShell, or just stick with Cygwin/Perl Scripts/Unix Shell scripts, etc. The benefit of PowerShell would be that the scripts could be more easily used by teammates that don't have cygwin; however, I don't know if I'd really be writing that many general purpose scripts, or if people would even use t...

Parsing each field and process it using 'awk'/'gawk'

Hi all, Here is a query: grep bar 'foo.txt' | awk '{print $3}' The field name emitted by the 'awk' query are mangled C++ symbol names. I want to pass each to dem and finally output the output of 'dem'- i.e the demangled symbols. Assume that the field separator is a ' ' (space). ...

What goodies are present in UNIX shells sans BASH?

I have been using 'bash' since the time I have been using Unix- Linux/Solaris. Now, I am interested to know what do shells like 'ksh','zsh' offer better? What do 'geeks' use? ...

Good book to learn Unix API?

Hello, I would love to learn to program in pure UNIX with C kernell calls and all this, but I basically don't know where to start... Books are usually the best way, so that's why I'm asking for one - but some good online material would be OK too. But please, no wikipedia - I don't want an encyclopedia, I want some book to guide me throu...