# locks on serial port

## cloc3

I'm plaiyng from a short time with an arduino uno board.

On my system, when two different processes (for example two istances of cat /dev/arduino, from the same owner) read from the arduino serial port, the second one hangs, waiting for the first process. No error is shown on the terminal.

On a independent ubuntu envinronment, instead, both processes work together (more slowly, off course).

How may I switch between these different behaviours?

----------

## tomtom69

look at "man setserial", the options ^session_lockout and ^pgrp_lockout could be the thing you are looking for.

Try to modify /etc/serial.conf or use setserial directly.

----------

## cloc3

thanks.

setserial was not installed on my systems.

anyway, adding it, I have this output:

```

cloc3@dell ~ $ setserial -a /dev/arduino

/dev/arduino, Line 0, UART: unknown, Port: 0x0000, IRQ: 0

        Baud_base: 115200, close_delay: 50, divisor: 0

        closing_wait: 3000

        Flags: spd_normal low_latency

```

The only difference between ubuntu are: closing_wait and close_delay parameters (750 and 12 on ubuntu).

Appling this values has no effect.

session_lockout and pgrp_lockout status is not reported by setserial ouput and setting them seems not usefull.

----------

## tomtom69

From setserial output I assume the port to be a virtual one (USB serial)?

You are writing that two cat /dev/arduino processes work at one time on ubuntu. Is the output really duplicated, i.e. both cat processes show the same data?

The only thing I can imagine that there is some difference in file permissions for /dev/arduino (or if it is a symlink, the dev file symlinked to) or permissions of /var/lock. 

However I have never seen that data from a serial port is duplicated if two programs open the same port...

----------

## cloc3

this is a video on ubuntu.

this is what happens on /proc filesystem:

```

wiildos@ubuntu ~ $ ps axu|grep arduino

wiildos   5949  0.0  0.0   4224   284 pts/0    S+   19:57   0:00 cat /dev/arduino

wiildos   5950  0.0  0.0   4224   284 pts/4    S+   19:57   0:00 cat /dev/arduino

wiildos   6166  0.0  0.0   4408   828 pts/1    S+   20:01   0:00 grep --colour=auto arduino

wiildos@ubuntu ~ $ ls -l /proc/5949/fd/

totale 0

lrwx------ 1 wiildos wiildos 64 feb  8 20:01 0 -> /dev/pts/0

lrwx------ 1 wiildos wiildos 64 feb  8 20:01 1 -> /dev/pts/0

lrwx------ 1 wiildos wiildos 64 feb  8 20:01 2 -> /dev/pts/0

lr-x------ 1 wiildos wiildos 64 feb  8 20:01 3 -> /dev/ttyACM0

wiildos@ubuntu ~ $ ls -l /proc/5950/fd/

totale 0

lrwx------ 1 wiildos wiildos 64 feb  8 20:02 0 -> /dev/pts/4

lrwx------ 1 wiildos wiildos 64 feb  8 20:02 1 -> /dev/pts/4

lrwx------ 1 wiildos wiildos 64 feb  8 20:01 2 -> /dev/pts/4

lr-x------ 1 wiildos wiildos 64 feb  8 20:02 3 -> /dev/ttyACM0

```

----------

## tomtom69

This looks like the data is spread (randomly) between the two instances of "cat". Is this really a desired behaviour?

Normally file locking prevents such a behaviour. I would assume that the data sharing is only the effect of a non-functional file locking in ubuntu.

----------

## cloc3

 *tomtom69 wrote:*   

> Is this really a desired behaviour?
> 
> 

 

I don't know.

My wish is to switch between both behaviours.

 :Smile: 

Sometime, the ubuntu behaviour may it be useful. How may I investigate about it?

----------

## tomtom69

The only I know to share a dev file is via access control

http://www.makelinux.net/ldd3/chp-6-sect-6

But this needs to be done by the client, in your case "cat".

Someone here who has an idea how to achieve this using "cat" or set this as a default behaviour?

----------

## cloc3

 *tomtom69 wrote:*   

> 
> 
> But this needs to be done by the client, in your case "cat".
> 
> 

 

thanks a lot.

anyway, the problem is in the kernel.

forcing ubuntu to boot with gentoo kernel, the behaviour turns back to gentoo.

----------

## tomtom69

I could not find any suspicious config option that could enable this behaviour.

Does your Ubuntu kernel contain a .config file that can be compared to your Gentoo's kernel .config file?

Or can you compile a gentoo kernel identical to the Ubuntu one with the same .config file?

----------

## cloc3

 *tomtom69 wrote:*   

> 
> 
> Does your Ubuntu kernel contain a .config file that can be compared to your Gentoo's kernel .config file?
> 
> Or can you compile a gentoo kernel identical to the Ubuntu one with the same .config file?

 

thanks again.

unlikeley, your hint needs a lot of time.

surely, gentoo and ubuntu .config file are not completly identical.

----------

