Все вопросы: [unix]

1 243 вопросов

0
голосов
3ответов
205 просмотров

identify the exact header file

I am using some macro in my source file (*.c ) . Is there any way during compilation or from the library that I can identify the exact header file from which this particular macro is getting resolved ? The issue is we are using a macro #defined to 10 in some header file, but the value being re...

35
голосов
6ответов
31858 просмотров

Optimal lock file method

Windows has an option to open a file with exclusive access rights. Unix doesn't. In order to ensure exclusive access to some file or device, it is common practice in Unix to use a lock file usually stored in the /var/lock directory. The C instruction open( "/var/lock/myLock.lock", O_RDWR | O_...

1
голосов
2ответов
1208 просмотров

Simplest method to get the dictionary definitions of a list of words in a text file

File1: hello world I don't know the best method to extract a list of words from a text file, find their definitions and paste them into an output textfile. I've been thinking of using WordNet - but don't know how to automate the process. Does anyone have any ideas (perhaps google/APIs/linux a...

15
голосов
3ответов
8307 просмотров

Duplicate file descriptor with its own file offset

How can one create a new file descriptor from an existing file descriptor such that the new descriptor does not share the same internal file structure/entry in the file table? Specifically attributes such as file offset (and preferably permissions, sharing and modes) should not be shared between ...

34
голосов
8ответов
85277 просмотров

How to run PHP exec() as root?

I'm trying to build a firewall manager in PHP, but when I execute, <?php exec('iptables -L'); ?>, the result array is empty. I have tried, <?php echo exec('whoami'); ?>, and the response is www-data (the user that Apache is using). What can I do to execute the exec function as root? ...

2
голосов
5ответов
2751 просмотров

C++ Serial Port Question

Problem: I have a hand held device that scans those graphic color barcodes on all packaging. There is a track device that I can use that will slide the device automatically. This track device functions by taking ascii code through a serial port. I need to get this thing to work in FileMaker on a ...

12
голосов
2ответов
8858 просмотров

What is a good book/guide for socket programming in C?

Could anybody please tell me which is best guide/book/material for socket programming in C? I am reading beej's guide for network programming but it just gives an overview. Can you suggest any other books or guides?

1
голосов
6ответов
8049 просмотров

C format specifier question

While I was working i came across a code which was written by somebody else. i see a statement as , sprintf(o_params->o_file_name, "%s_%s_%04.4d_%s_%s.ASC", "OUTD", "RM", sequence_no, DateStamp_buf1, TimeStamp_buf1 ); In the above statement, I see %04.4d. Is this a correct...

1
голосов
5ответов
7497 просмотров

Remove strings after each first word in a text file

File1: hello (OPTION1) 123456 123456 123456 world (OPTION1) 123456 123456 123456 foo (OPTION1) 123456 123456 123456 bar (OPTION1) 123456 123456 123456 How would one remove each string after each first word in the textfile File1? This would probably be down...

10
голосов
4ответов
23180 просмотров

Use sed to delete all leading/following blank spaces in a text file

File1: hello world How would one delete the leading/trailing blank spaces within this file using sed - using one command (no intermediate files)? I've currently got: sed -e 's/^[ \t]*//' a > b For leading spaces. sed 's/ *$//' b > c And this for trailing spaces.

79
голосов
10ответов
64270 просмотров

Is there any simple way to benchmark python script?

Usually I use shell command time. My purpose is to test if data is small, medium, large or very large set, how much time and memory usage will be. Any tools for linux or just python to do this?

0
голосов
3ответов
15194 просмотров

How to use sed to delete a string with wildcards

File1: <a>hello</b> <c>foo</d> <a>world</b> <c>bar</d> Is an example of the file this would work on. How can one remove all strings which have a <c>*</d> using sed?

12
голосов
4ответов
4796 просмотров

How do I write a unix filter in python?

I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars x from stdin.

2
голосов
3ответов
2645 просмотров

How to delete partial duplicate lines with AWK?

I have files with these kind of duplicate lines, where only the last field is different: OST,0202000070,01-AUG-09,002735,6,0,0202000068,4520688,-1,0,0,0,0,0,55 ONE,0208076826,01-AUG-09,002332,316,3481.055935,0204330827,29150,200,0,0,0,0,0,5 ONE,0208076826,01-AUG-09,002332,316,3481.055935,0204330...

0
голосов
3ответов
512 просмотров

Keep shell open with PHP to allow multiple calls?

How can I allow the shell session to stay open until I close it with PHP? In my example I want to use NcFtp to publish some files through shell command. I want to leave PHP's built in FTP because it is much much slower and performance is an issue. It is easy to use ncftpput to publish a file or...

2
голосов
6ответов
617 просмотров

How to determine where code spends a lot of time in a kernel space (system calls)

I noticed that 10% my code run is system space. However I do NOT know which system calls. I suspect, though, it is either has to do files or timestamps. Is there a tool to figure out which system calls are the culprits? Also, I want to know the frequency of (and location) of calls (and callee) ...

20
голосов
6ответов
3301 просмотров

Good collection of libraries for C?

I'm looking for a good collection of libraries for ANSI-C, stuff for handling vectors, hash maps, binary tress, string processing, etc.

0
голосов
2ответов
1546 просмотров

Error in msgrcv: Invalid Arguments

I am writing a code in C on a unix system. I have created a message queue server. Each time I receive a new message I fork and the child process handles the new client. The server waits for new client. Here's the code. for (;;) { struct my_msgbuf buf; if (msgrcv (msqid, &(buf.m...

3
голосов
5ответов
2227 просмотров

Bourne shell script to convert a number to telephone format

I want to change a number such as 1234567890 to 456-7890; is there a way to do this in Unix Shell programming?

101
голосов
1ответов
88730 просмотров

Insert the carriage return character in vim

I'm editing a network protocol frame stored a file in Unix (\n newlines). I need to insert the carriage return character (U+000D aka \r). When I try to paste it from the clipboard ("+p) or type it using Ctrl+Shift+u-000d, the linefeed is inserted (U+000A). What is the right way to do it?

2
голосов
4ответов
7495 просмотров

Output on a single line

The following code is working as expected. But I can not format the output. It will print something like this: mysql test someDB I want the output on a single line mysql test someDB I tried using sed in the script but it did not work. #!/bin/sh for dbName in `mysqlshow -uroot -pPassWord |...

6
голосов
2ответов
5459 просмотров

Paste two text lists (one list a file) into one list separated by semicolon

An example of the process/output would be: File1: hello world File2: foo bar Resulting file after concatenation: File3: hello;foo world;bar For a large list of non-predictive text (no-wild cards - but lines are aligned as above). I cannot figure out how to do this with the paste comma...

4
голосов
4ответов
298 просмотров

POSIX Threads: are pthreads_cond_wait() and others systemcalls?

The POSIX standard defines several routines for thread synchronization, based on concepts like mutexes and conditional variables. my question is now: are these (like e.g. pthreads_cond_init(), pthreads_mutex_init(), pthreads_mutex_lock()... and so on) system calls or just library calls? i know t...

0
голосов
11ответов
5590 просмотров

Get filename from Unix "ls -la" command with regexp?

How can I produce a regular expressions pattern that returns the filename from any one of these lines? (I will search one line at a time). drwxrwxrwx 4 apache apache 4096 Oct 14 09:40 . drwxrwxrwx 11 apache apache 4096 Oct 13 11:33 .. -rwxrwxrwx 1 apache apache ...

73
голосов
9ответов
37075 просмотров

ASCII Library for Creating "Pretty" Directory Trees?

Is there some *nix tool or perl/php library that will let you easily create directory tree visualizations that look like the following? www |-- private | |-- app | | |-- php | | | |-- classes | | | +-- scripts | | |-- settings | | +-- sql | +-- lib | ...

0
голосов
2ответов
577 просмотров

symbolic link to bit bucket

How do I throw the contents of binary log to bit bucket? I tried to create a soft link but it did not work. I do not want to save mysql general log but I want to watch it using tail -f command. ln -s /dev/null /var/log/mysql/mysql-gen.log ln: creating symbolic link /var/log/mysql/mysql-gen.lo...

0
голосов
2ответов
122 просмотров

dealing with files in php

I am creating a file with php. I just want to be able to create it, with no content, under a directory. Then I want to be able to edit it when I access my server with ftp. I can't! The user of php is different from the ftp user, and this last one does not have permissions to change it! I tried ch...

2
голосов
2ответов
3231 просмотров

unix sockets: how to send really big data with one "send" call?

I'm using unix scoket for data transferring (SOCK_STREAM mode) I need to send a string of more than 100k chars. Firstly, I send length of a string - it's sizeof(int) bytes. length = strlen(s) send(sd, length, sizeof(int)) Then I send the whole string bytesSend = send(sd, s, length) but fo...

1
голосов
2ответов
679 просмотров

PHP regex to limit new lines to a maxmium of two

I'm using this but it's replacing single occurances of a new line with <br/><br/> function nl2br2($string){ $string = preg_replace('/(\r\n){2,}/', '<br/><br/>', $string); //$string = preg_replace('/[\r\n]/', '<br/>', $string); return $string; } It happ...

1
голосов
5ответов
9463 просмотров

Best tool in unix for viewing large files

I am a novice in unix. I am facing a problem in viewing big log files in unix using vi. Could you please suggest the best tool for fast viewing of big files on unix? Additionally, could you to post your own ways of viewing the big files on unix?