system-calls

How can I make the system call write() print to the screen?

感情迁移 提交于 2019-12-02 20:49:48
For my OS class I'm supposed to implement Linux's cat using only system calls (no printf) Reading this reference I found it being used to print to a file. I guess I should manipulate ofstream. In the example appears: ofstream outfile ("new.txt",ofstream::binary); How can I make it write to the screen? EDIT: I realized this write() is part of iostream library, is this the same as the int write (int fd, char *buf , int size) system call? Write to the file descriptor for standard output or standard error (1 and 2 respectively). A system call is a service provided by Linux kernel. In C programming

How does a system call work [duplicate]

北战南征 提交于 2019-12-02 20:47:53
This question already has answers here : How is the system call in Linux implemented? (6 answers) How does system calls work ? What are the operations happen during system call? There are various system call like open , read, write, socket etc. I would like to know how do they work in general ? In short, here's how a system call works: First, the user application program sets up the arguments for the system call. After the arguments are all set up, the program executes the "system call" instruction. This instruction causes an exception : an event that causes the processor to jump to a new

How can I get a list of Linux system calls and number of args they take automatically?

情到浓时终转凉″ 提交于 2019-12-02 20:37:16
I writing a Linux system call map for the radare2 debugger. This means providing a huge static array mapping system call number to a syscall name name and the number of arguments it takes. This was easy for OpenBSD as the syscall numbers are defined in sys/syscall.h and in a comment above each is the number of args. It was just a matter of writing a script to parse this and throw out the C code for the array. On linux however, we do not have this luxury. It is easy to get the syscall number from the kernel headers, but how should I get the number of args? The only ideas I have are: 1) Type

Golang catch signals

拟墨画扇 提交于 2019-12-02 19:20:42
I want to implement a "process wrapper" in Go. Basically what it will do, is launch a process (lets say a node server) and monitor it (catch signals like SIGKILL, SIGTERM ...) I think the way to do is to launch the node server in a go routine using syscall.Exec : func launchCmd(path string, args []string) { err := syscall.Exec(path, args, os.Environ()) if err != nil { panic(err) } } Then I'd like to catch every possible signals generated by the command executed by syscall . I'm pretty new to Go, any help would be appreciated. Luke There are three ways of executing a program in Go: syscall

Starting another program via system() call blocks the socket

一世执手 提交于 2019-12-02 19:07:08
问题 I searched google and StackOverflow for anything similar to this but the closest ones were C code and the situation wasn't the same... I have a program which starts another one via cstdlib's system() call to a script and everything works fine, the problem is when I have to test new code, so I stop execution (Crtl+C and kill -9 pid produce the same error), compile the new executable and try to run it again, that's when I get the message that the socket is already in use. My program uses an

How to Dynamically Allocate Memory Using Assembly and System Calls Under Linux

ぃ、小莉子 提交于 2019-12-02 19:02:44
I'm looking for some good code examples of dynamic memory allocation using an assembly language under Linux and using system calls, not malloc and friends. What are some of the simplest but effective ways to do this? On Intel 386+ computers. brk(2) . And take a look at ELF . On Linux mmap2 is a sensible system call to use for this at a low level. It takes 6 arguments, so in IA32 you can call it using: mov eax, 192 ; mmap2 xor ebx, ebx ; addr = NULL mov ecx, 4096 ; len = 4096 mov edx, $7 ; prot = PROT_READ|PROT_WRITE|PROT_EXEC mov esi, $22 ; flags = MAP_PRIVATE|MAP_ANONYMOUS mov edi, -1 ; fd =

System calls on Windows

南楼画角 提交于 2019-12-02 18:26:32
I just want to ask, I know that standart system calls in Linux are done by int instruction pointing into Interrupt Vector Table. I assume this is similiar on Windows. But, how do you call some higher-level specific system routines? Such as how do you tell Windows to create a window? I know this is handled by the code in the dll, but what actually happend at assembler-instruction level? Does the routine in dll calls software interrupt by int instruction, or is there any different approach to handle this? Thanks. Making a Win32 call to create a window is not really related to an interrupt. The

Prompting for user input in assembly ci20 seg fault

大兔子大兔子 提交于 2019-12-02 18:17:06
问题 I am currently working on a small program on a ci20 machine that prompt the user for a integer value then print the value to the screen. My current code .data prompt: .asciiz "Please enter an integer: " message: .asciiz "\nValue entered: " .text .global main main: addiu $sp, $sp, -4 # push stack sw $ra, ($sp) # save return address addi $v0, $0, 4 la $a0, prompt syscall # printing prompt addi $v0, $0, 5 syscall # get user input move $t0, $v0 # save input in $t0 move $a0, $v0 addi $v0, $0, 1 #

How to set ulimit -n from a golang program?

拜拜、爱过 提交于 2019-12-02 17:47:14
My purspose was to set ulimit -n from within a golang program so that I do not have to set it globally but restrict it within the program. Found systemcalls setrlimit and get rlimit for the same. ( http://linux.die.net/man/2/setrlimit ) But when I tried a sample program for the same I was getting an error saying invalid argument while setting the value. package main import ( "fmt" "syscall" ) func main() { var rLimit syscall.Rlimit err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) if err != nil { fmt.Println("Error Getting Rlimit ", err) } fmt.Println(rLimit) rLimit.Max = 999999 rLimit

How to map an empty file using mmap

[亡魂溺海] 提交于 2019-12-02 17:00:53
问题 I am trying to create an empty file if it does not exists. And than map it using mmap() so, that i can pass it to my other program for writing. I am not sure which arguments for mmap are suitable for an empty file. My code works for non empty files but gives error "Invalid argument" if file is empty Code program1 (only creates an empty file if not exists) int i; int fd = open("/home/sungmin/dummy_programs/dummy.txt", O_RDONLY | O_CREAT, 0777); char *pmap; pid_t child; if (fd == -1) { perror(