system-calls

How to find which type of system call is used by a program

梦想与她 提交于 2019-12-09 13:30:53
问题 I am working on x86_64 machine. My linux kernel is also 64 bit kernel. As there are different ways to implement a system call (int 80, syscall, sysenter), i wanted to know what type of system call my machine is using. I am newbie to linux. I have written a demo program. #include <stdio.h> int main() { getpid(); return 0; } getpid() does one system call. Can anybody give me a method to find which type of system call will be used by my machine for this program.. Thank you.... 回答1: victory:~ #

Difference between nice and setpriority in unix

假如想象 提交于 2019-12-09 10:14:45
问题 I'm trying to implement a different flavor of the 'nice' command of unix in C. I have seen the definitions of nice() system call and setpriority() call. The nice() call only increments/decrements the priority of the process. If I want to set the priority of a process to a particular value, can't I use the nice() call? Basically, other than how the priority is modified, is there any difference between nice() and setpriority() ? 回答1: It's historical. nice() was introduced long before

How to obtain detailed device / partition info from file path on Linux (like UUID, hard drive serial etc.)

妖精的绣舞 提交于 2019-12-09 08:56:03
问题 Starting with an absolute file path, I want to obtain the following information: The mount point of the filesystem on which the file is stored (in order to compute the path relative to the mount point) The UUID and label of the file system The type (or vendor name) and the serial number of the hard drive that contains the partition I am aware that 2 and 3 may be undefined in many cases (e.g. for loopback, ramfs, encyrpted devices), which is totally fine. I also know how to obtain that

How to disassemble a system call

与世无争的帅哥 提交于 2019-12-09 03:28:00
问题 If I have the virtual address of system call, can I disassemble that system call? I want to do it on running kernel to find what all address are handled by the particular system call while running. I am running 32 bit 2.6.38 kernel (x86). 回答1: I am not sure you question is very meaningful. Please read more about system calls, kernels, operating systems, linux, and the linux kernel Essentially, a system call is (from the application point of view) an atomic operation implemented by one machine

Capture vDSO in strace

感情迁移 提交于 2019-12-08 17:40:06
问题 I was wondering if there is a way to capture (in other words observe) vDSO calls like gettimeofday in strace . Also, is there a way to execute a binary without loading linux-vdso.so.1 (a flag or env variable)? And lastly, what if I write a program that delete the linux-vdso.so.1 address from the auxiliary vector and then execve my program? Has anyone ever tried that? 回答1: You can capture calls to system calls which have been implemented via the vDSO by using ltrace instead of strace . This is

Show the list of running processes in C

邮差的信 提交于 2019-12-08 14:21:44
问题 Can you suggest me a system call that retrieves the current running processes? (I have to write a C function like top) I tried to read the proc/ folder but is not good in my case. 回答1: The only way to do that on Linux is to access the /proc/ pseudo-file system. Remember that /proc/ files are not "real" files on disk, so I/O (i.e. reading /proc/ files) is quite fast. Read proc(5) man page. You could use libprocps which is reading /proc/ The ps and top (and htop etc...) commands are all using

Compiling kernel error: stdio.h: No such file or directory

末鹿安然 提交于 2019-12-08 11:24:04
问题 I am making SYSTEM CALL for linux 2.6.39 kernel. I have completed all the edits in the files. Now When i am trying to compile the kernel it is showing this error : error: stdio.h: No such file or directory If i remove stdio.h, Will the system call work ??? My code is #include<stdio.h> #include <linux/linkage.h> asmlinkage long sys_atvfcfs(int at[], int bt[], int n) { int i=0; int j,t,wt[n],sum,q; float avgwt; for(j=i+1;j<n;j++) { if(at[i]>at[j]) { t=at[i]; at[i]=at[j]; at[j]=t; q=bt[i]; bt[i]

Add new system call at FreeBSD 10.1

风格不统一 提交于 2019-12-08 08:19:23
问题 I wanna add new system call at FreeBSD. My system call code is: #include <sys/types.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/proc.h> #include <sys/mount.h> #include <sys/sysproto.h> int Sum(int a, int b); int Sum(a,b) { int c; c = a + b; return (0); } But when I rebuild the kernel, I have an error: What's wrong? Can you help me? Thanks a lot. 回答1: Here's how I did it with my example system call of setkey which takes two unsigned ints. I added my

Differences between C write call and Go syscall.Write

和自甴很熟 提交于 2019-12-08 06:51:11
问题 syscall write returns -1 and set errno is a trivial case. I am interested in the status of errno if C write call returning zero or positive. The wrapper syscall.Write in Go simply returns err if errno is not zero for any case, which also includes the case of write call returns positive. https://github.com/golang/go/blob/3cb64ea39e0d71fe2af554cbf4e99d14bc08d41b/src/syscall/zsyscall_linux_386.go#L1007 However, the man page of C write call roughly describes errno may also be set but unspecified

Why does System.console() return null for a command line app? [duplicate]

会有一股神秘感。 提交于 2019-12-08 05:34:22
问题 This question already has answers here : System.console() returns null (11 answers) Closed 5 years ago . I am working on a legacy app which depends on user command line input: String key = System.console().readLine("Please enter the license key: "); However, I am getting a NullPointerException because System.console() gives me a null. Why does System.console() return null for a command line app? It happens when running it out of the terminal as well as IDE. 回答1: If you start java from a