# Select() return -1,errno=1. run filebeat by golang code

**URL:** https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969
**Category:** Beats
**Tags:** filebeat
**Created:** [November 23, 2018, 7:54am UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969 "2018-11-23T07:54:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zhaoya881010](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zhaoya881010](https://discuss.elastic.co/u/zhaoya881010)
#### Post date: [November 23, 2018, 7:54am UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/1 "2018-11-23T07:54:23Z")

</div>

i found question," select return -1,error=1", run filebeate in my instance.  
test code:  
main.go:

package main

/\*  
#include \<sys/types.h\>  
#include \<sys/socket.h\>  
#include \<stdio.h\>  
#include \<netinet/in.h\>  
#include \<arpa/inet.h\>  
#include \<unistd.h\>  
#include \<stdlib.h\>  
#include \<sys/time.h\>  
#include \<sys/ioctl.h\>  
#include \<errno.h\>  
#include "demo\_interface.h"  
void init(){  
int client\_sockfd = socket(AF\_INET, SOCK\_STREAM, 0);  
struct sockaddr\_in address;  
address.sin\_family = AF\_INET;  
address.sin\_addr.s\_addr = inet\_addr("192.168.194.37");  
address.sin\_port = htons(10095);  
int len = sizeof(address);  
int result = connect(client\_sockfd, (struct sockaddr \*)&address, len);  
if (result != 0){  
printf("connect error:%d\n",result);  
return;  
}  
struct timeval tv;  
fd\_set readfds;  
while(1){  
tv.tv\_sec=3;  
tv.tv\_usec=0;  
FD\_ZERO(&readfds);  
FD\_SET(client\_sockfd,&readfds);  
result = select(FD\_SETSIZE,&readfds,NULL,NULL,&tv);  
if (-1 ==result){  
printf(" select error:%d\n",errno);  
continue;  
}  
if(0 == result){  
printf("select time out\n");  
continue;  
}  
if( FD\_ISSET(client\_sockfd,&readfds)){  
printf("client\_sockfd is event:%d\n",client\_sockfd);  
FD\_CLR(client\_sockfd,&readfds);  
continue;  
}  
}

}  
\*/  
import "C"  
import \_ "fmt"  
import "time"  
import "GoProxy/module/beats/filebeat"

func main() {  
go func() {  
time.Sleep(10 \* time.Second)  
filebeat.Start1()  
}()  
C.init()

```
select {}

```

}

filebeat\_instance.go:

import "fmt"  
import "[github.com/elastic/beats/filebeat/cmd](http://github.com/elastic/beats/filebeat/cmd)"  
func Start1() {  
if err := cmd.RootCmd.Execute(); err != nil {  
fmt.Println("error.....:", err.Error())  
}  
}

result:  
10s before  
client\_sockfd is event 3  
client\_sockfd is event 3  
client\_sockfd is event 3  
client\_sockfd is event 3  
client\_sockfd is event 3

10s after,filebeat is run  
select error:1  
select error:1  
select error:1  
select error:1  
select error:1  
select error:1  
select error:1  
select error:1

[zhaoya@localhost test]$ ll /proc/122571/fd  
total 0  
lr-x------. 1 zhaoya zhaoya 64 Nov 23 02:54 0 -\> pipe:[1358645]  
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 1 -\> pipe:[1358646]  
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 2 -\> pipe:[1358647]  
lrwx------. 1 zhaoya zhaoya 64 Nov 23 02:54 3 -\> socket:[1360307]  
lrwx------. 1 zhaoya zhaoya 64 Nov 23 02:54 4 -\> anon\_inode:[eventpoll]  
l-wx------. 1 zhaoya zhaoya 64 Nov 23 02:54 5 -\> /home/zhaoya/go/src/GoProxy/test/filebeat/logs/filebeat

i dont'know question case. can you help me?

---

<div class="post-metadata">

### Author: ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)
#### Post date: [November 26, 2018, 8:31am UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/2 "2018-11-26T08:31:09Z")

</div>

What is the problem with using the package `exec` to run Filebeat? [How use Stop method?](https://discuss.elastic.co/t/how-use-stop-method/155833/5?u=kvch)

---

<div class="post-metadata">

### Author: ![zhaoya881010](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zhaoya881010](https://discuss.elastic.co/u/zhaoya881010)
#### Post date: [November 26, 2018, 8:38am UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/3 "2018-11-26T08:38:21Z")

</div>

i don't want to have two processes.filebeat or my app. so i used "cmd.RootCmd.Execute();" method. but select() I/O is bad after filebeat runs.

---

<div class="post-metadata">

### Author: ![zhaoya881010](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zhaoya881010](https://discuss.elastic.co/u/zhaoya881010)
#### Post date: [November 26, 2018, 8:44am UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/4 "2018-11-26T08:44:53Z")

</div>

Using filebeat in the one process affects elect i/o multiplexing

---

<div class="post-metadata">

### Author: ![zhaoya881010](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zhaoya881010](https://discuss.elastic.co/u/zhaoya881010)
#### Post date: [November 27, 2018, 11:43pm UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/5 "2018-11-27T23:43:55Z")

</div>

@kvch i trying to embed filebeat inside my application.but i found my application is bad after runing filebeat.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 25, 2018, 11:43pm UTC](https://discuss.elastic.co/t/select-return-1-errno-1-run-filebeat-by-golang-code/157969/6 "2018-12-25T23:43:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
