Skip to content

Commit e5a9848

Browse files
committed
m
1 parent e6bda52 commit e5a9848

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/base/utils.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ long long current_time_m()
8787
return t;
8888
}
8989

90-
int save_pid(char * path) {
90+
int save_pid(const char * path) {
9191
pid_t pid = getppid();
9292
FILE *fp = fopen(path, "w+");
9393
if (!fp) {
9494
printf("open file fail\n");
9595
return 0;
9696
}
97-
fwrite(&pid, sizeof(pid), 1, fp);
97+
char str[10];
98+
sprintf(str, "%d", pid);
99+
fwrite(str, strlen(str), 1, fp);
98100
fclose(fp);
99101
fp = NULL;
100102

‎src/base/utils.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern "C" {
1313
#endif /* __cplusplus */
1414

15-
15+
#include <stdio.h>
1616
#include <time.h>
1717
#include <sys/time.h>
1818
#include <sys/types.h>
@@ -94,7 +94,7 @@ long long current_time_m();
9494
/**
9595
* 保存进程id
9696
*/
97-
int save_pid(char * path);
97+
int save_pid(const char * path);
9898

9999
#ifdef __cplusplus
100100
}

‎src/exe/vlrtmp.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Poco/Base64Decoder.h"
1414
#include "Poco/Exception.h"
1515

16+
#include "base/utils.h"
1617
#include "h264/NetH264Reader.h"
1718
#include "rtmp/RTMPOutPutStream.h"
1819
#include "encoder/FLVEncoder.h"
@@ -58,6 +59,9 @@ int main(int argc, char **argv) {
5859
std::stringstream instr;
5960
instr << argv[2];
6061
instr << randomstr();
62+
string pid_path(argv[0]);
63+
pid_path = pid_path + ".pid";
64+
save_pid(pid_path.c_str());
6165
if (write_url(instr.str().c_str())) {
6266
RTMPOutPutStream output(instr.str().c_str(), true);
6367
FLVEncoder encoder(&reader, &output);

0 commit comments

Comments
 (0)