c语言:fprintf pid_t

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <getopt.h>
static pid_t PidOutPut (char *path)
{
  FILE *fp;
  pid_t pid;

  pid = getpid();

  fp = fopen (path, "w");
  if (fp != NULL)
    {
      fprintf (fp, "%d\n", (int) pid);
      fclose (fp);
      return -1;
    }
  return pid;
}
int main()
{
  pid_t op;
  op =  PidOutPut("/home/lyd/mywork/pid/abc");
  printf("%d",(int)op);
}

 

posted on 2021-01-19 17:11  lydstory  阅读(148)  评论(0)    收藏  举报

导航