unix-programming

can any user change uid/gid using setuid()/setgid?

or only root can? I want to change the uid/gid of an non-root from a .sh script by calling setuid/setgid. Is it possible? ...

How do I properly reference the GNU readline library to scan terminal input?

I am attempting to compile C code that utilizes the following within GNU readline. #include <readline/readline.h>; #include <readline/history.h>; I've tried changing the <> to "" and compiling both with and without the -lreadline options. Nothing seems to work. When compiling without -lreadline under gcc results in the following being...

signal acknowledgement

how to kill a child process on sending an interrupt with key stroke and then sending a signal to parent that the child process has been killed? ...

How to delete text delimited by { and }

hello, I am new to UNIX programming and had the following problem with UNIX vi editor. Can you please tell me the UNIX command required to delete text delimited by { and } where both characters occur after the current cursor position. Thanks. ...

return common fields in two files

Hi, I have two files, should compare 1st column of file1 with 1st column of file2 and the resultant file should be file2 For example: file1 apple banana Mango potato tomato file 2 apple:fruit brinjal: vegetable lady's finger: vegetable orange: fruit tomato: vegetable potato: vegetable Resultant file should look something like th...

size_t or long for the size of a string containing a file?

Suppose I want to read an entire file in memory. I'd open it in binary mode, use fseek to get to the end of the file, then do ftell to get its size. Then I would allocate a string with the same size as the file, and just read it in, right? The problem is that ftell returns a long int, and malloc should receive a size_t argument. Now, si...

ENOENT while creating a UNIX socket in Ruby

I'm trying to create a socket in Ruby using require "socket" w = UNIXSocket.new("socket") and I keep running into No such file or directory - socket (Errno::ENOENT) This looks completely backwards to me, because new() is supposed to create that missing file. What am I missing? ...

How can I code a monitor in C?

Hello, I need to do some process synchronization in C. I want to use a monitor, and I have read a lot about them. However I have been unable to find out how to implement one in C. I have seen them done in Java and other languages like C++, but I am unable to find examples in C. I have looked through K&R and there is no example in there...

adding word to a field common to all records in a file

Hi, I want to add a word to field 1 of a file separated by space,for example My file,containing two fields: apple:fruit:tree orange:fruit:tree mango:fruit:tree brinjal:vegetable:plant potato:vegetable:root now I want to add word "family" separated by space to the field 1. Therefore, the resultant file should look some thing like t...

difference between the content of two files

I have two files one file subset of other and i want to obtain a file which has contents not common to both.for example File1 apple mango banana orange jackfruit cherry grapes eggplant okra cabbage File2 apple banana cherry eggplant cabbage The resultant file, difference of above two files mango orange jackfruit grapes okra An...

Recursive file delete in C on Linux

I have a C program that, at one point in the program has this: system("rm -rf foo"); Where foo is a directory. I decided that, rather than calling system, it would be better to do the recursive delete right in the code. I assumed a piece of code to do this would be easy to find. Silly me. Anyway, I ended up writing this: #include ...

Can I execute a multiline command in Perl's backticks?

In Unix, I have a process that I want to run using nohup. However this process will at some point wait at a prompt where I have to enter yes or no for it to continue. So far, in Unix I have been doing the following nohup myprocess <<EOF y EOF So I start the process 'myprocess' using nohup and pipe in a file with 'y' then close the fil...

A linux version of cygwin?

I'm looking for a linux program that is simple and text-based, like cygwin, thats actually linux. I feel to much is missed out by cygwin like nano syntax highlighting and general linux programs. Is there any thing that runs with command prompt, like cygwin, that is a full text-based linux OS. ...

How to create required file name in unix using shell script

I am reading one property file which contains some file paths using shell script. Now depending on this file path I want to create name of zip file. Something like this...My property file contents:: path=tmp/inputs/logs/abc path=tmp/backup/inte/xyz destpath=abc/xyz Now I am able to create file name as abc.zip and xyz.zip as: paths=`g...

Good book for Unix Internals

Hi all, am very much interested in unix. Want to learn in and out. Can you guys help me by listing some books which can make me a wizard? Ultimately I want to become a unix programmer. I am not a novice user in Unix. ...

unix shell set command

Want to know what set -A option does in the below command? XMLOUTFILE=${XMLOUTDIR}/${TEST_ID} set -A FILES "${XMLOUTFILE}" ...

Anonymous Structures in C found in Unix Kernel

I have started reading the Lions Commentary on Unix v6. I came across these snippets, which I have never seen used in the C language. The author does provide some sort of an explanation, but could someone explain to me what is happening here? params.h : SW 0177570 ...... struct { int integ; }; and this used in unix/prf.c if(SW->int...

In UNIX what "cat file1 > file1 does?"

When the output of a command is redirected to a file, the output file is created or truncated by the shell before the command is executed, any idea what cat foo > foo does? ...

Launch terminal from eclipse

Hi, I recently switched to Eclipse (Helios) for my programming needs, and I like it very much. There is just on thing that is driving me crazy, how can I launch (compile and run) my code into the native mac osx terminal. I tried creating an "external tools configuration", but that just starts the terminal without outputting the applic...

how to run quota in UNIX ?

Hi, I am using ubuntu in my machine and wanting to run the command quota -v. So, I install quota by typing in sudo apt-get install quota. When I type in quota -v, it doesn't show any information. only commands that works is quota -h and quota -V. could you please tell me if I have to anything else to make quota -v to work? Thanks a lot....