Skip to content

Commit 24c4d0c

Browse files
committed
syscall_example1.c created online with Bitbucket
1 parent 022d2e8 commit 24c4d0c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<errno.h>
2+
#include<asm/unistd.h>
3+
#include<unistd.h>
4+
#include<stdio.h>
5+
#include<stdlib.h>
6+
#include "syscallmacros.h"
7+
8+
extern char **environ;
9+
10+
_syscall3(ssize_t,write,int,fd,const void *,buf,size_t,count)
11+
12+
_syscall3(long,open,const char *,filename,int,flags,int,mode)
13+
14+
_syscall0(pid_t,getpid)
15+
16+
17+
int main()
18+
{
19+
20+
21+
int ret,ret1;
22+
23+
char str[1024];
24+
25+
ret = snprintf(str,sizeof(str), "the pid of the process is %d\n", getpid());
26+
27+
ret1 = write(STDOUT_FILENO,str,ret+1);
28+
29+
if(ret1<0){ perror("error in write syscall"); exit(1);}
30+
31+
ret1 = getpid();
32+
33+
34+
if(ret1<0){ perror("error in open syscall"); exit(2);}
35+
36+
exit(0);
37+
}

0 commit comments

Comments
 (0)