unix

Issues with special character '<' in Bash string?

試著忘記壹切 提交于 2020-01-25 08:48:08
问题 I am making a shell script that takes an optional standard input. I have a snippet of the code below. ${file} is just a fileName that is written in a txt file containing a list of all file names. $2 in this case would be another program (a shell script too). if [ -f ${file}.in ]; then #if ${file}.in exists in current directory stdIn="< ${file}.in" #set optional stdIn fi if ! [ -f ${file}.args ]; then #if ${file}.args does not exist in curr directory $2 $stdIn > ${file}.out #run the $2 program

Creating a multi-level pipe for Linux commands

早过忘川 提交于 2020-01-25 08:03:14
问题 I'm trying to create a multi-level pipe, where the input is Linux commands (e.g. ls | sort) and the output is just the regular output when typed into a Linux console (essentially just use execlp to execute the commands). I've attempted to create a program that works for 1 and 2 levels, but I can't seem to get the 2 level one to work, specifically with the command "ls | sort". The program just freezes. I also don't know how to continue beyond that and add more levels (required to support 16

Is the ln(create hardlink) command atomic on AIX?

亡梦爱人 提交于 2020-01-25 07:08:06
问题 Is the ln(create hardlink) command atomic on AIX? The problem is that there are two processes running and the process that creates the hardlink is not the same process that reads it. I want to ensure that the second process will not run into trouble with partially created hardlinks if there is such a thing. See also: Copy or move file into directory with parallel processing from another process 来源: https://stackoverflow.com/questions/59894407/is-the-lncreate-hardlink-command-atomic-on-aix

Copying files containing specific text in its content from a folder to other

↘锁芯ラ 提交于 2020-01-25 00:07:08
问题 At times I have come across a situation whereby I have to copy all the files containing a specific pattern in its content from a folder to another. For example, DirA contains 100 files, out of which there are 60 files which contains a pattern FOO . My requirement is to copy these 60 files from DirA to DirB . I typically write a small shell script to do this job and it works properly. However, I am trying to understand if there is a way to it only using a combination of some commands such that

UNIX环境编程学习笔记(26)——多线程编程(一):创建和终止线程

风格不统一 提交于 2020-01-24 21:10:01
lienhua34 2014-11-08 在 进程控制三部曲 中我们学习了进程的创建、终止以及获取终止状态等的进程控制原语。线程的控制与进程的控制有相似之处,在表 1中我们列出了进程和线程相对应的控制原语。 表 1: 进程原语和线程原语的比较 进程原语 线程原语 描述 fork pthread_create 创建新的控制流 exit pthread_exit 从现有的控制流中退出 waitpid pthread_join 从控制流中得到退出状态 atexit pthread_cleanup_push 注册在退出控制流时调用的函数 getpid pthread_self 获取控制流的 ID abort pthread_cancel 请求控制流的非正常退出 1 线程 每个线程都有一个线程 ID,线程只在它所属的进程环境中有效。线程ID 使用pthread_t 表示。可以通过调用pthread_self 函数获取线程自身的线程 ID, #include <pthread.h> pthread_t pthread_self(void); 返回值:调用线程的线程ID 线程 ID 不一定是一个非负整数,也有可能是一个结构体。所以,要对比两个线程是否相同,必须使用pthread_equal 函数来进行, #include <pthread.h> int pthread_equal(pthread

Can't find c++ libraries on unix

丶灬走出姿态 提交于 2020-01-24 19:45:07
问题 I've written a simple c++ program, test.cpp: #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; cout << s << endl; return 0; } Why does runnning gcc test.cpp -o mytest give me these errors, and more? Undefined symbols for architecture x86_64: "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from: _main in cc8rGYVq.o "std::cin", referenced from: _main in cc8rGYVq.o 回答1: Don't use the executable named

capability of `posix_spawn`

会有一股神秘感。 提交于 2020-01-24 12:56:51
问题 I'm writing a small program which is somewhat a server that spawns its client programs (locally, not over the network) and do interesting things between them. While my primary OS in use is Linux, I expect this to run on other OSes including Windows. There is fork and exec which does the job, but when I port the program to Windows via cygwin, I don't want that crappy fork implemented in cygwin to kick in, which actually calls CreateProcess and copies the current process's memory area to the

capability of `posix_spawn`

怎甘沉沦 提交于 2020-01-24 12:55:47
问题 I'm writing a small program which is somewhat a server that spawns its client programs (locally, not over the network) and do interesting things between them. While my primary OS in use is Linux, I expect this to run on other OSes including Windows. There is fork and exec which does the job, but when I port the program to Windows via cygwin, I don't want that crappy fork implemented in cygwin to kick in, which actually calls CreateProcess and copies the current process's memory area to the

How to add a directory tree to a ClearCase repository in-place?

☆樱花仙子☆ 提交于 2020-01-24 12:18:29
问题 I previously asked this question regarding ClearCase, but it doesn't work when I have a private directory in a vob, and I want to add it recursively to the repository in-place. Is there any way to do that? 回答1: If you have a private directory, the nominal way would be to: rename it first (still keeping it in its same parent directory) use the new name of that directory as sources for your clearfsimport (that I describe in the SO question you mention in your question) That is not always ideal,

Is there an easy way of clearing a pipe in C

喜欢而已 提交于 2020-01-24 06:37:26
问题 I have a pipe that all my child processes use, but before a child uses the pipe to talk to the parent I need to clear it so that the parent reads from it correctly. Is there a simple function in C to do this? 回答1: The way to "clear" a pipe is to read from it until the buffer is empty. This doesn't help you. I am guessing that your real problem is that the parent might read data that is mixed from multiple clients. There are two easy solutions to your problem. Always write messages less than