Volad Malevich
@veficos how?😊
veficos
void gettime(char* buffer){
struct timeval time_now;
char ms[7];
gettimeofday(&time_now, NULL);
struct tm *time_str_tm = gmtime(&time_now.tv_sec);
strftime (buffer, 256, "%d.%m.%Y %H:%m:%S", time_str_tm);
sprintf(ms, ":%06ld", time_now.tv_usec);
strcat(buffer, ms);
}
Volad Malevich
@veficos In function ‘gettime’:
./bin/start.c:10:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
gettimeofday(&time_now, NULL);
veficos
#include <time.h>
#include <sys/time.h>
Anonymous
Volad Malevich
works great!!! Thanks a lot guys @veficos @vbextreme @ssynx 👍😊
Nazir
Hi
Volad Malevich
help again pls)
Volad Malevich
i need to get result of system("ps -A") to variable
Volad Malevich
is it possible?
klimi
veficos
u can use pipe to receive result..
Joe
please help. I included a header file in my project and everything compiles without a problem, but when using the functions from the header file it says undefined reference to (function)
Volad Malevich
please help me to get result of system("ps -A") to variable via PIPE or other way. I found some in google, but it's not exactly what i need.
Volad Malevich
?
veficos
like:
int pid;
int fds[2];
pipe(fds);
pid = fork();
if(pid == 0){
close(1);
dup2(fds[1], 1);
close(fds[0]);
execlp("ps", "ps", "-a", NULL);
} else {
char buffer[8192*16] = {0};
while (1) {
char buf[1024];
int n = read(fds[0], buf, 1024);
if (n <= 0) {
break;
}
memcpy(buffer, buf, n);
if (n != 1024) { break; }
}
printf("%s\n", buffer);
}
Volad Malevich
Volad Malevich
how to make a function with return output to buffer?
Volad Malevich
void output(char *buffer) ?
veficos
that's ok
Volad Malevich
return what?
veficos
void output(char *buffer)
{
int pid;
int fds[2];
pipe(fds);
pid = fork();
if(pid == 0){
close(1);
dup2(fds[1], 1);
close(fds[0]);
execlp("ps", "ps", "-a", NULL);
} else {
while (1) {
char buf[1024];
int n = read(fds[0], buf, 1024);
if (n <= 0) {
break;
}
memcpy(buffer, buf, n);
if (n != 1024) { break; }
}
}
}
...
char buffer[8192*16] = {0};
output(buffer);
Volad Malevich
Volad Malevich
is execlp fits to do it?
Volad Malevich
for example "ps -A -o args | grep stop | grep 1765"
Anonymous
return what?
You may return exit value if you want
Anonymous
(Exit value of the child process)
veficos
system() instead of execlp()
Volad Malevich
)) i need this one
Volad Malevich
var = output("system command");
Volad Malevich
i need this one, where output is a void output() function
Volad Malevich
veficos
void output(char* command, char *buffer)
{
int pid;
int fds[2];
pipe(fds);
pid = fork();
if(pid == 0){
close(1);
dup2(fds[1], 1);
close(fds[0]);
system(command);
} else {
while (1) {
char buf[1024];
int n = read(fds[0], buf, 1024);
if (n <= 0) {
break;
}
memcpy(buffer, buf, n);
if (n != 1024) { break; }
}
}
}
...
char buffer[8192*16] = {0};
output("ps aux", buffer);
Volad Malevich
Shalom
,
Anonymous
Thanks
klimi
Welcome
Thespartann
Thespartann
That's only one
klimi
2 to write
Marie
Felix has 1/3 warnings... watch out!
Reason for last warn:
advertisement
Anonymous
Yeah sure!
Morgan
Ибраги́м
BinaryByter
Dev C++
BinaryByter
no, C-Free
Mihail
BinaryByter
nothing that i'd be proud of, tbh
Mihail
Says it in the top bar of the window
Mr. COwO2 Preis
> windows
Mihail
BinaryByter
> windows
windows ten, to make the matters worse
BinaryByter
using a windows XP theme
BinaryByter
xD
BinaryByter
using C unironically
Ибраги́м
C-Free 4.0
CodeLite
QtCreator
CodeBlocks
?
BinaryByter
C-Free 4.0
Mr. COwO2 Preis
Zero
Can Anybody Teach me Linked Lists...how they work?
Zero
After declaring Struct node...i dont understood anything
BinaryByter
Vim
you non-practical moster
Mihail
What do you guys think about him and emacs?
BinaryByter
BinaryByter
Mihail
I'd like to learn about one of these
Mr. COwO2 Preis
try emacs or vim
Mihail
So I can program via ssh in my PC at home
Mr. COwO2 Preis
Mihail
BinaryByter
vsc