Skip to content

Commit fd8d18e

Browse files
committed
syscall_example2.c created online with Bitbucket
1 parent 24c4d0c commit fd8d18e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#define _GNU_SOURCE
2+
#include<unistd.h>
3+
#include<stdio.h>
4+
#include<stdlib.h>
5+
#include<sys/syscall.h>
6+
#include<sys/types.h>
7+
8+
9+
int main()
10+
{
11+
12+
int ret,ret1;
13+
14+
char str[1024];
15+
16+
ret = snprintf(str,sizeof(str), "the pid of the process is %d\n", getpid());
17+
18+
ret1 = syscall(SYS_write,STDOUT_FILENO,str,ret+1);
19+
20+
if(ret1<0){ perror("error in write syscall"); exit(1);}
21+
22+
ret1 = syscall(SYS_getpid);
23+
24+
25+
if(ret1<0){ perror("error in open syscall"); exit(2);}
26+
27+
exit(0);
28+
29+
}
30+
31+
32+
33+

0 commit comments

Comments
 (0)