# Process exited

**URL:** <https://forum.sierrawireless.com/t/process-exited/11985>\
**Category:** Uncategorized\
**Created:** [February 2, 2015, 9:33am UTC](https://forum.sierrawireless.com/t/process-exited/11985 "2015-02-02T09:33:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfrancois](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@dfrancois](https://forum.sierrawireless.com/u/dfrancois)\
**Post date:** [February 2, 2015, 9:33am UTC](https://forum.sierrawireless.com/t/process-exited/11985/1 "2015-02-02T09:33:34Z")

</div>

Hi,

I’am facing to an issue with the write(int fd, char\* buffer, size\_t length) function.

I wrote a simple code that writes some bytes on a socket. It works fine until the server closed the connection.  
Actually, when the connection is closed by the server, instead of returning -1 the write function “crashed” and the process is killed.

Here are legato logs:

```auto
00:52:29 INFO | supervisor[565]/security T=main | proc.c proc_SigChildHandler() 1253 | Process 'helloWorld' (PID: 10771) has exited due to signal 13.
00:52:29 -WRN- | supervisor[565]/security T=main | proc.c GetFaultAction() 1142 | Unrecognized fault action for process 'helloWorld'. Assume fault action is 'ignore'.
00:52:29 *CRT* | supervisor[565]/security T=main | app.c app_SigChildHandler() 1439 | The process 'helloWorld' in app 'Test' has faulted and will be ignored in accordance with its fault policy.
00:52:29 INFO | supervisor[565]/security T=main | app.c app_SigChildHandler() 1483 | app 'Test' has stopped.
00:52:29 INFO | supervisor[565]/security T=main | sandbox.c sandbox_Remove() 1257 | 'Test' sandbox removed.
00:52:29 INFO | supervisor[565]/supervisor T=main | supervisor.c DeleteAppObj() 487 | Application 'Test' has stopped.
```

And here the code of my (test) application:

[code]  
int sock; // socket fd

static int sock\_connect() {  
struct addrinfo \*addrInfo;  
struct addrinfo hints = { 0, AF\_UNSPEC, SOCK\_STREAM, IPPROTO\_TCP, 0, NULL, NULL, NULL };

```
int res;
errno = 0;

if ((res = getaddrinfo("10.41.51.205", "1234", &hints, &addrInfo)) != 0) {
	LE_ERROR("Cannot get address info: %s\n", gai_strerror(res));
	return -1;
}
sock = socket(addrInfo->ai_family, addrInfo->ai_socktype, addrInfo->ai_protocol);
if (sock == -1) {
	LE_ERROR(" Cannot create socket: %s\n", strerror(errno));
	return -1;
}

if (connect(sock, addrInfo->ai_addr, addrInfo->ai_addrlen) == -1) {
	LE_ERROR(" Cannot connect to server: %s\n", strerror(errno));
	return -1;
}
freeaddrinfo(addrInfo);
LE_DEBUG("Connected to server");
return 0;

```

}

COMPONENT\_INIT {  
if (sock\_connect() == 0) {  
int n = 0;  
while (n \>= 0) {  
n=write(sock, “hello\n”, 6);  
sleep(2);  
}  
}  
}[/code]

The application is connected to a netcat server running on my laptop: netcat -l -p 1234

Here are netcat “logs”:

```auto

[/cnetcat -l -p 1234
hello
hello
hello
hello
^C // I manually killed the server => My legato app crashed with log quoted before 
```

I there something wrong in my code ? or is this a legato / or stdlib bug ?  
If so how can I worked around this problem ?

Many thanks for your help !

David

---

<div class="post-metadata">

**Author:** ![amitchell](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/amitchell/32/2760_2.png) [@amitchell](https://forum.sierrawireless.com/u/amitchell)\
**Post date:** [February 3, 2015, 9:46am UTC](https://forum.sierrawireless.com/t/process-exited/11985/2 "2015-02-03T09:46:09Z")

</div>

Hi David,

you need to handle SIGPIPE when you use write with a socket. See the glibc documentation at [gnu.org/software/libc/manual … nding-Data](http://www.gnu.org/software/libc/manual/html_node/Sending-Data.html#Sending-Data)

You can either use a native signal handler or use our signals API. [legato.io/legato-docs/15\_01/c\_signals.html](http://www.legato.io/legato-docs/15_01/c_signals.html)

Regards,  
Andrew

---

<div class="post-metadata">

**Author:** ![dfrancois](https://avatars.discourse-cdn.com/v4/letter/d/9e8a1a/32.png) [@dfrancois](https://forum.sierrawireless.com/u/dfrancois)\
**Post date:** [February 17, 2015, 9:28am UTC](https://forum.sierrawireless.com/t/process-exited/11985/3 "2015-02-17T09:28:34Z")

</div>

Thanks for your help Andrew !

It helped me to solve my problem
