Linux

How to build a swift executable for Linux on macOS

你。 提交于 2021-02-18 22:28:06
问题 I am trying to build a swift executable on my MacBook for my Linux vServer. I already tried using swiftc -target "x86_64-linux test.swift , but my macOS swift compiler shows this error: <unknown>:0: error: unable to load standard library for target 'x86_64--linux' So I looked around and found this question: Swift on OS X compiling for Linux? and tried out this example script from apple to setup a cross-platform toolchain. After trying to build a module like shown in the example text of the

How to print the next word after a found pattern with grep,sed and awk?

北城余情 提交于 2021-02-18 22:26:28
问题 for example, suppose I have logfile.txt which contains "Here is a sample text file" My pattern is "sample" How can I get the word next to sample in my logfile.txt. 回答1: Here is one way to do it with awk: $ awk '{for(i=1;i<=NF;i++)if($i=="sample")print $(i+1)}' file text Explained: $ awk '{ for(i=1;i<=NF;i++) # process every word if($i=="sample") # if word is sample print $(i+1) # print the next }' file and sed: $ sed -n 's/.* sample \([^ ]*\).*/\1/p' file text ie. after sample next space

Is there a way to find performance of individual functions in a process using perf tool?

安稳与你 提交于 2021-02-18 22:25:50
问题 I am trying to get performance of individual functions within a process. How can I do it using perf tool? Is there any other tool for this? For example, let's say, main function calls functions A , B , C . I want to get performance of main function as well as functions A,B,C individually . Is there a good document for understating perf source code? Thank you. 回答1: What you want to do is user-land probing. Perf can only do part of it. Try sudo perf top -p [pid] and then watch the scoreboard.

Avoiding page faults in IDT hooking

故事扮演 提交于 2021-02-18 22:12:37
问题 Note: I'm running on FreeBSD, but I've also included Linux as a tag since the problem is somewhat general and Linux-specific solutions are of interest to me. Edit : just to confirm that the issue was not FreeBSD specific, I ported the module to Linux, and indeed got the exact same behavior. The code for the Linux version of the module is given below; it is essentially exactly the same, the only major difference being that the IDT is evidently given read-only protection in Linux, and so I had

Linux - Without hardware soundcard, capture audio playback, and record it to file

二次信任 提交于 2021-02-18 22:10:32
问题 Is such a thing even possible? Is there a possibility to create a virtual sound card and then use for example PyAudio to listen to its output and save it to a file? NOTE that there is no hardware soundcard present on the machine. I have tried a lot of things, especially snd-dummy ALSA module, but I am starting to doubt if I am looking for the right tools. I would be grateful if someone could point me towards at least high-level solution. Preferably something that would work on Ubuntu server.

How to check if a file is already opened in C

梦想的初衷 提交于 2021-02-18 21:12:33
问题 I am working on a multithreaded system where a file can be shared among different threads based on the file access permissions . How can I check if file is already opened by another thread. Thanks in advance 回答1: To find out if a named file is already opened on linux, you can scan the /proc/self/fd directory to see if the file is associated with a file descriptor. The program below sketches out a solution: DIR *d = opendir("/proc/self/fd"); if (d) { struct dirent *entry; struct dirent *result

Stack alignment on x86

有些话、适合烂在心里 提交于 2021-02-18 21:12:17
问题 I had a mysterious bus error that occurred, on a x86 (32-bit) platform, when running code compiled with gcc-4.8.1 with -march=pentium4 . I traced the problem to an SSE instruction: movdqa %xmm5,0x50(%esp) with esp = 0xbfffedac. movdqa requires the address to be 16-byte aligned, which is not the case here, thus the bus error. The problem does not occur if compiling with -march=native (this is a Core-i3 processor). As far as I know, the only stack alignment guaranteed on Linux/x86 is 4-byte.

How to check if a file is already opened in C

早过忘川 提交于 2021-02-18 21:12:10
问题 I am working on a multithreaded system where a file can be shared among different threads based on the file access permissions . How can I check if file is already opened by another thread. Thanks in advance 回答1: To find out if a named file is already opened on linux, you can scan the /proc/self/fd directory to see if the file is associated with a file descriptor. The program below sketches out a solution: DIR *d = opendir("/proc/self/fd"); if (d) { struct dirent *entry; struct dirent *result

Affect the order of NetworkInterface.getNetworkInterfaces enumeration in Java 6 on Linux

丶灬走出姿态 提交于 2021-02-18 21:11:44
问题 What is the order in which NetworkInterface.getNetworkInterfaces() returns an enumeration of network interfaces? Is there a way to affect that on JVM level or on Linux OS level? 回答1: According to the source of the OpenJDK (found in src/solaris/native/java/net/NetworkInterface.c, method enumInterfaces ) it will return IPv4 interfaces first (method enumIPv4Interfaces ), followed by IPv6 interfaces (method enumIPv6Interfaces ). The order within those categories seems to be the same that the OS

How can I use ant <exec> to execute commands on linux?

房东的猫 提交于 2021-02-18 20:42:05
问题 I would like to use ant to exectue a command like below: <exec executable="echo ptc@123 | sudo -S /app/Windchill_10.0/Apache/bin/apachectl -k stop"> </exec> But it replies an error say The ' characters around the executable and arguments are not part of the command. The background is: I want to use ant to stop the apache server but it doesn't installed by the same user I run the command. Anyone could help or give me some clues? Thanks in advance 回答1: Ant's <exec> task uses Java's Process