system-calls

How to make a call to an executable from Python script?

雨燕双飞 提交于 2019-11-27 14:44:30
问题 I need to execute this script from my Python script. Is it possible? The script generate some outputs with some files being written. How do I access these files? I have tried with subprocess call function but without success. fx@fx-ubuntu:~/Documents/projects/foo$ bin/bar -c somefile.xml -d text.txt -r aString -f anotherString >output The application "bar" also references to some libraries, it also create the file "bar.xml" besides the output. How do I get access to these files? Just by using

What is the difference between `read` and `sysread`?

↘锁芯ラ 提交于 2019-11-27 13:58:05
read and sysread have very similar documentation. What are the differences between the two? About read : read supports PerlIO layers. read works with any Perl file handle [1] . read buffers. read obtains data from the system in fixed sized blocks of 8 KiB [2] . read may block if less data than requested is available [3] . About sysread : sysread doesn't support PerlIO layers (meaning it requires a raw a.k.a. binary handle). sysread only works with Perl file handles that map to a system file handle/descriptor [4] . sysread doesn't buffer. sysread performs a single system call. sysread returns

What is the difference between the functions of the exec family of system calls like exec and execve?

你离开我真会死。 提交于 2019-11-27 12:52:02
问题 I have been following a system programming course recently and I came through the system calls exec() and execve() . So far I cannot find any difference between these two, Even the Wikipedia does not give a clear explanation, so is there a difference between exec() and execve() . And someone please could give brief descriptions about exec family system calls such as execl() , execv() , execle() , execvp() . 回答1: Use man exec and read: The execv(), execvp(), and execvpe() functions provide an

Is “asmlinkage” required for a c function to be called from assembly?

痞子三分冷 提交于 2019-11-27 11:18:26
问题 I am writing a C function that will be invoked from assembly code. (Specifically, I want to do some checking job in the path of system call handling in linux kernel, so I will call the c function before a system call is dispatched in entry_32.S) I am confused with the "asmlinkage" modifier when defining my c function. I know asmlinkage is to tell the compiler that the parameters will be passed through stack. #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) Questions: (1) Is

system call and context switch

对着背影说爱祢 提交于 2019-11-27 09:21:39
问题 I am sorry to ask this question when it has already been asked but I couldn't get a clarity from them. So I am asking the following related questions to get the difference between system call (mode-switch) and context switch Why is it said that the system call doesn't require context switch when the context of the process making the call has to be saved and then reloaded. Is it just because according to the definition of context switch a switch has to be made to another process. What does it

basic assembly not working on Mac (x86_64+Lion)?

和自甴很熟 提交于 2019-11-27 09:19:44
here is the code(exit.s): .section .data, .section .text, .globl _start _start: movl $1, %eax movl $32, %ebx syscall when I execute " as exit.s -o exit.o && ld exit.o -o exit -e _start && ./exit" the return is "Bus error: 10" and the output of " echo $? " is 138 I also tried the example of the correct answer in this question: Process command line in Linux 64 bit stil get "bus error"... First, you are using old 32-bit Linux kernel calling convention on Mac OS X - this absolutely doesn't work. Second, syscalls in Mac OS X are structured in a different way - they all have a leading class

Why does returning from _start segfault?

流过昼夜 提交于 2019-11-27 08:47:36
问题 I tried to put code not in the main function, but directly into _start : segment .text global _start _start: push rbp mov rbp, rsp ; ... program logic ... leave ret Compile: yasm -f elf64 main.s ld -o main main.o Run: ./main Segmentation fault(core dumped) I read, leave is mov esp,ebp pop ebp But why is it that such an epilogue to the pop stack frame and the set base frame pointer to a previous frame's base results in a segmentation fault? Indeed, making an exit system call exits gracefully.

How do 2 or more fork system calls work?

三世轮回 提交于 2019-11-27 08:44:13
问题 Here's a code where I use 2 fork() system calls one after another - How does it actually work? #include <unistd.h> #include <iostream.h> using namespace std; int main() { cout << "0. I am process " << getpid() << endl; (void) fork(); cout << "1. I am process " << getpid() << endl; (void) fork(); cout << "2. I am process " << getpid() << endl; } I get the output as : 0. I am process 27701 1. I am process 25915 1. I am process 27701 2. I am process 27781 2. I am process 26170 2. I am process

How to print a character in Linux x86 NASM?

我与影子孤独终老i 提交于 2019-11-27 08:18:03
问题 I'm trying to print a single character or a number using NASM , targeting an x86 GNU/Linux architecture. Here's the code I'm using: section .text global _start _start: ; Linux printing preparation mov eax,4 mov ebx,1 ; Print 'A' character mov ecx,'A' ; ecx should contain the value to print mov edx,1 ; edx should contain how many characters to print int 80h ; System exit mov eax,1 mov ebx,0 int 80h Running this code, however, prints nothing. What am I doing wrong? 回答1: ecx should contain a

Is there a better way than parsing /proc/self/maps to figure out memory protection?

折月煮酒 提交于 2019-11-27 07:52:06
On Linux (or Solaris) is there a better way than hand parsing /proc/self/maps repeatedly to figure out whether or not you can read, write or execute whatever is stored at one or more addresses in memory? For instance, in Windows you have VirtualQuery . In Linux, I can mprotect to change those values, but I can't read them back. Furthermore, is there any way to know when those permissions change (e.g. when someone uses mmap on a file behind my back) other than doing something terribly invasive and using ptrace on all threads in the process and intercepting any attempt to make a syscall that