system-calls

Calling a non python program from python?

那年仲夏 提交于 2019-11-28 04:45:21
问题 I am currently struggling to call a non python program from a python script. I have a ~1000 files that when passed through this C++ program will generate ~1000 outputs. Each output file must have a distinct name. The command I wish to run is of the form: program_name -input -output -o1 -o2 -o3 To date I have tried: import os cwd = os.getcwd() files = os.listdir(cwd) required_files = [] for i in file: if i.endswith('.ttp'): required_files.append(i) So, I have an array of the neccesary files.

How are sbrk/brk implemented in Linux?

前提是你 提交于 2019-11-28 04:44:52
I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" ( struct vm_area_struct ). There is also a structure which represents (again in a very high level view) a process' whole address space ( struct mm_struct ). Each process (except some kernel threads) has

How do I use a Linux System call from a Linux Kernel Module

て烟熏妆下的殇ゞ 提交于 2019-11-28 04:14:41
问题 I am having some difficulty calling a system call from inside a Linux Kernel Module. The system calls have been tested and work properly from a standard c user space program but I can't seem to get the kernel module to compile and run them. In my user program I include the following code and the system call works: #include <linux/unistd.h> #define __NR_sys_mycall 343 extern long int _syscall(long int_sysno,...)__THROW; //and then a simple call is done as such long value = syscall(__NR_sys

getrandom syscall in C not found

时光毁灭记忆、已成空白 提交于 2019-11-28 03:28:54
问题 The problem was resolved by upgrading the C library. I would like to use the syscall getrandom (http://man7.org/linux/man-pages/man2/getrandom.2.html) gcc-5 -std=c11 test.c #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> #include <errno.h> #include <string.h> #include <signal.h> #include <linux/random.h> #include <sys/syscall.h> int main(void) { void *buf = NULL; size_t l = 5; unsigned int o = 1; int r = syscall(SYS_getrandom, buf, l, o); return 0; } or int main(void) {

Anyone can understand how gettimeofday works?

不羁岁月 提交于 2019-11-28 00:25:28
问题 gettimeofday is a syscall of x86-86 according to this page(just search gettimeofday in the box): int gettimeofday(struct timeval *tv, struct timezone *tz); I thought the disas should be easy anough, just prepare the two pointers and call the related syscall . But its disas is doing much more: (gdb) disas gettimeofday Dump of assembler code for function gettimeofday: 0x00000034f408c2d0 <gettimeofday+0>: sub $0x8,%rsp 0x00000034f408c2d4 <gettimeofday+4>: mov $0xffffffffff600000,%rax

How does execve call dynamic linker/loader (ld-linux.so.2)

只愿长相守 提交于 2019-11-28 00:12:22
I used gcc to compile and link the most basic C program, test.c: int main() { } As expected, the output is a dynamically linked executable: $ file test test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x0f806c099f74132a158d98aebde4639ae0998971, not stripped Running strace gives the following output: $ strace -f ./test execve("./test", ["./test"], [/* 31 vars */]) = 0 brk(0) = 0x248d000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE

How do I read the results of a system() call in C++?

时光毁灭记忆、已成空白 提交于 2019-11-27 22:49:16
问题 I'm using the following code to try to read the results of a df command in Linux using popen . #include <iostream> // file and std I/O functions int main(int argc, char** argv) { FILE* fp; char * buffer; long bufSize; size_t ret_code; fp = popen("df", "r"); if(fp == NULL) { // head off errors reading the results std::cerr << "Could not execute command: df" << std::endl; exit(1); } // get the size of the results fseek(fp, 0, SEEK_END); bufSize = ftell(fp); rewind(fp); // allocate the memory to

What happens if a write system call is called on same file by 2 different processes simultaneously

。_饼干妹妹 提交于 2019-11-27 22:42:38
问题 Does the OS handle it correctly? Or will I have to call flock()? 回答1: Although the OS won't crash, and the filesystem won't be corrupted, calls to write() are NOT guarenteed to be atomic, unless the file descriptor in question is a pipe, and the amount of data to be written is PIPE_MAX bytes or less. The relevant part of the standard: An attempt to write to a pipe or FIFO has several major characteristics: Atomic/non-atomic: A write is atomic if the whole amount written in one operation is

Implementing Linux System Call using LKM

让人想犯罪 __ 提交于 2019-11-27 22:38:33
问题 I was trying to add a new System Call to linux kernel 3.2.x. While searching for useful reference material over the internet i had an impression that implementing system call as a loadable module is not possible as in SO question Is it possible to add a system call via a LKM? I found another link which says this "There is a way to add system calls without recompiling the kernel using modules as a wrapper, but that is beyond the scope of this document". source http://hekimian-williams.com/?p

What is the interface for ARM system calls and where is it defined in the Linux kernel?

旧街凉风 提交于 2019-11-27 20:17:12
I have read about system calls in Linux, and everywhere description is given regarding x86 architecture (ox80 interrupt and SYSENTER). But I am not able to track down the files and process for a system call in ARM achitecture. Can anyone please help. Few relevant files which I got to know are: \arch\arm\kernel\calls.S \arch\arm\kernel\entry-common.S (explanation needed) In ARM world, you do a software interrupt (mechanism to signal the kernel) by supervisor call / svc (previously called SWI). ARM assembly (UAL) syntax looks like this: SVC{<c>}{<q>} {#}<imm> (In Linux you need to pass #0) You