unix-programming

Static library depending on shared library

I have created a communication library which is linked statically into several different applications. The library provides support for communication via different kinds of hardware. Some of the hardware is supported from the vendor via a shared library. On systems without those kinds of hardware, the shared library is not available. Pr...

shell script help - checking for file exists

I'm not sure why this code isn't working. Its not going to the copy command. I successfully run this manually on the command line (without the check) I don't think i'm performing a correct file check? Is there a better, cleaner way to write this? I just want to make sure the file exists, if so, copy it over. Thanks. #!/bin/bash if [ $...

Fork() on iPhone

Does the the iPhone SDK allow fork() and pipe(), the traditional unix functions? I can't seem to make them working. Edit Problem solved. Here, I offer a solution to anybody who encounters problems similar to me. I was inspiried by the answers in this thread. In iPhone, there is no way to fork a process. However, it's not impossible to...

difference between static and dynamic library in unix..

what is the difference between static and dynamic library in unix? how can i use libraries in unix? ...

i want to know if the ide we use contains linker or not

Is the Linker part of the Operating System or the Compiler/IDE? ...

C and memory alignment for a binary protocol

I will use this code as an example: typedef struct __attribute__((aligned(XXX),packed)) { uint16_t type; uint32_t id_index; } a_msg; void write_func(){ a_mesg mymsg mymsg.type = htons(1); mymsg.id_index = htonl(5); write(sock_fd, &mymsg, sizeof(a_mesg)); } void read_func(){ a_mesg mymsg read(sock_fd, &mymsg, si...

How can I create a thread in unix?

How can one create a thread in unix programming? What is difference between forking and threading? Is threading more useful than forking? ...

Adding User and Group in Unix

Hi, Does anyone know the api for adding users and groups in unix and removing them ? I want to do this programatically. Thanks, Frank ...

a program to monitor a directory on Linux

There is a directory where a buddy adds new builds of a product. The listing looks like this $ ls path-to-dir/ 01 02 03 04 $ where the numbers listed are not files but names of directories containing the builds. I have to manually go and check every time whether there is a new build or not. I am looking for a way to automate this, s...

grep user name in unix

Hi ! I want to grep the username. the command id gives the following. id output is uid=0(root) gid=0(root) but i want the output as only root or who ever the user is. ...

UNIX tty command and file command ?

Hi, I am new to UNIX and when I was reading a book about UNIX, I came across following two problems that I didn't understand. I would really appreciate your help. 1) Look up the man page for the file command, and then use it on all files in the /dev directory. Can you group these files into two categories? 2) Run the tty command, and ...

how to read file line by line in shell script and store each line in a variable.

hi all, i am new in unix. i have to write a shell script which read a file line by line and store it in a separate variable. my text file contents multiple source path and one destination path. something like this:: source_path=abc/xyz source_path=pqr/abc desination_path=abcd/mlk number of source path can vary. I dont have much hands ...

Creating a daemon with stop, start functionality in C

How to add daemon stop, start and report function to this daemon code? #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <syslog.h> #include <string.h> int main(void) { /* Our process ID and Session ID */ pid_t pid, sid...

execv, select and read

Hello, I am creating a child-parent fork() to be able to communicate with a shell(/bin/sh) from the parent through a pipe. The problem is: In a parent I set a select() on a child output, but it unblocks only when the process is finished! So when I run say ps it's okay. but when I run /bin/sh it does not output until shell exits. But I ...

what does 0 indicate in socket() system call?

hi.. what 0 indicates in following line? what are other flags i can use? server = socket(AF_UNIX, SOCK_STREAM, 0) ...

how to use a nested if and perform correct file checks in unix

Need some shell scripting help, especially with my if-then-else logic. I want to combine both conditions, but not sure if the file checks will work the same? Should I be doing something like a nested if?? My script uses the if statements to do file checks to see if they exist, then do something.. There is probably a better way to do fi...

problems combining files using unix cat and zcat in shell script

I've got a problem with my shell script. I am basically trying to create a new log file from (2) files using unix (zcat, cat) commands FileA = gzipped logfile (.gz) FileB = non-gzipped log file (.log) FileC = new file from FileA:FileB My problem is with FileC. For example: FileA has timestamp data from Aug19-Sept3 FileB has timest...

how to move files from one path to another path in unix using shell-script

Hi All, i want to move logs files from one path(source path) to another path(destination path). This source path and destination path is present in one text file. as:: source_path=abc/xyz source_path=pqr/abc desination_path=abcd/mlk so i read this file and stored paths in different variables.i have multiple source path so i s...

Using Visual Studio 2010, how do I provide input to a Visual C++ Win32 Console Application?

I am using Visual Studio 2010 Pro for simple C programming, I would like to know how I can provide input to the program without having to manually do so. The enviroment I am used to working is your standard commandline Unix enviroment. Once I compile a C file call "inputsInts" it becomes "a.out" and to test input I would type: The easy ...

Regarding UNIX Variable Date Format

Hi, I have a date value stored in a unix korn shell variable VALUE="2010_09_23" I want to change it to "23-Sep-2010" and store it in VALUE1. How can i do it? VALUE1="23-Sep-2010" ...