c example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int writeInfo(char* info)
{
    int fd = open("/a.txt", O_RDWR);

    write(fd,info,strlen(info));

    close(fd);
    return 0;
}

int writePid() {
        int pid;
        char* szBuffer = (char *)malloc(sizeof(int) + 1);
        memset(szBuffer, 0, sizeof(int) + 1);
        pid = getpid();
        sprintf(szBuffer, "%d", pid);
        writeInfo(szBuffer);
}


void main() {
    writeInfo("--------pid inside nsexec--------\n");
    writePid();
    writeInfo("\n");
}

Published 218 original articles · won praise 165 · Views 1.03 million +

Guess you like

Origin blog.csdn.net/x_i_y_u_e/article/details/88636154