unix

How do I find my program's main(…) function?

怎甘沉沦 提交于 2020-01-12 16:21:07
问题 I am currently porting a project with a few hundred code files and dependencies onto several third-party libraries to Mac Os. I've finally gotten to the point where the program compiles without warnings or errors, but it does not seem to execute my own main function. Instead it seems to execute some other main function which seems to belong to a third party. This function writes some diagnostic-looking data to the console and exits afterwards: (gdb) continue Current language: auto; currently

Unix cut except last two tokens

Deadly 提交于 2020-01-12 11:47:38
问题 I'm trying to parse file names in specific directory. Filenames are of format: token1_token2_token3_token(N-1)_token(N).sh I need to cut the tokens using delimiter '_' , and need to take string except the last two tokens. In above examlpe output should be token1_token2_token3 . The number of tokens is not fixed. I've tried to do it with -f#- option of cut command, but did not find any solution. Any ideas? 回答1: With cut: $ echo t1_t2_t3_tn1_tn2.sh | rev | cut -d_ -f3- | rev t1_t2_t3 rev

Linux/Unix Socket Self-connection

流过昼夜 提交于 2020-01-12 10:35:28
问题 When a client try to connect to a server, if client and server are both localhost, self-connection may happen(source port and destination port happened to be the same.). But my problem is, client is not listening to that port, how can self-connection be possible? 回答1: I found your question after encountering the same phenomenon. The best explanation I found is at Everything About Nothing: TCP Client Self Connect. You can ask for the port assigned to you via getsockname() and compare it to the

Access /Private/etc with c

我与影子孤独终老i 提交于 2020-01-12 10:30:11
问题 this might be a simple question, but how do I "request" system / root priviliges from the user in a c console application. I need to write to /Private/etc but i can't. This is for mac / unix. I've seen it being used in other console commands e.g. when you run the following command: "sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder", Terminal asks you for your Password. How do I do this? thanks, JNK 回答1: There isn't any system call which will let a process obtain root

Can the find command's “exec” feature start a program in the background?

ⅰ亾dé卋堺 提交于 2020-01-12 10:26:06
问题 I would like to do something like: find . -iname "*Advanced*Linux*Program*" -exec kpdf {} & \; Possible? Some other comparable method available? 回答1: Firstly, it won't work as you've typed, because the shell will interpret it as find . -iname "*Advanced*Linux*Program*" -exec kpdf {} & \; which is an invalid find run in the background, followed by a command that doesn't exist. Even escaping it doesn't work, since find -exec actually exec s the argument list given, instead of giving it to a

How to rename() without race conditions?

大城市里の小女人 提交于 2020-01-12 07:58:45
问题 If I want to rename A to B , but only if B doesn't exist, the naive thing would be checking if B exists (with access("B", F_OK) or something like that), and if it doesn't proceeding with rename . Unfortunately this opens a window during which some other process might decide to create B , and then it gets overwritten - and even worse there's no indication that something like that ever happened. Other file system access functions don't suffer from this - open has O_EXCL (so copying files is

shell script remote execution using python

白昼怎懂夜的黑 提交于 2020-01-12 07:51:09
问题 Is there a way that I can use Python on Windows to execute shell scripts which are located on a remote Unix machine? P.S: Sorry about the late edit. I do know of Paramiko, but I wanted to know if there is way of doing it without it. For starters, could it be done with subprocess()? 回答1: There is not any 'batteries included' module for remote shell execution in python. I'd suggest looking into Fabric , which provides a really nice interface for working through SSH on remote machines, probably

shell script remote execution using python

拟墨画扇 提交于 2020-01-12 07:51:04
问题 Is there a way that I can use Python on Windows to execute shell scripts which are located on a remote Unix machine? P.S: Sorry about the late edit. I do know of Paramiko, but I wanted to know if there is way of doing it without it. For starters, could it be done with subprocess()? 回答1: There is not any 'batteries included' module for remote shell execution in python. I'd suggest looking into Fabric , which provides a really nice interface for working through SSH on remote machines, probably

Unix: prepending a file without a dummy-file?

跟風遠走 提交于 2020-01-12 07:37:29
问题 I do not want: $ cat file > dummy; $ cat header dummy > file I want similar to the command below but to the beginning, not to the end: $ cat header >> file 回答1: You can't append to the beginning of a file without rewriting the file. The first way you gave is the correct way to do this. 回答2: This is easy to do in sed if you can embed the header string directly in the command: $ sed -i "1iheader1,header2,header3" Or if you really want to read it from a file, you can do so with bash's help: $

Building a Python shared object binding with cmake, which depends upon external libraries

只谈情不闲聊 提交于 2020-01-12 05:43:04
问题 We have a c file called dbookpy.c, which will provide a Python binding some C functions. Next we decided to build a proper .so with cmake, but it seems we are doing something wrong with regards to linking the external library 'libdbook' in the binding: The CMakeLists.txt is as follows: PROJECT(dbookpy) FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) INCLUDE_DIRECTORIES("/usr/local/include") LINK_DIRECTORIES(/usr/local/lib) OPTION(BUILD_SHARED