locking

Unlock Android phone programmatically?

折月煮酒 提交于 2019-12-01 02:25:21
问题 I want to write the code on how to unlock the Android Phone programmatically. I want lock or unlock the phone when the user taps the proximity sensor. public class MyActivity extends Activity{ private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF"; BroadcastReceiver myReceiver; Context context; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); context = this; final IntentFilter

create a lock file in bash to avoid duplicate execution

六眼飞鱼酱① 提交于 2019-12-01 01:13:55
I'm not very good on bash I've been modifying a code to create a lock file so a cron don't execute a second time if the first process hasn't finish. LOCK_FILE=./$(hostname)-lock (set -C; : > $LOCK_FILE) 2> /dev/null if [ $? != "0" ]; then echo "already running (lock file exists); exiting..." exit 1 fi trap 'rm $LOCK_FILE' INT TERM EXIT when I run it for the first time I get the message already running as if the file already existed. Perhaps I'm missing something #!/bin/sh ( # Wait for lock on /tmp/lock flock -x -w 10 200 || exit 127 # you can use or not use -w #your stuff here ) 200> /tmp/lock

Cross-platform and cross-process atomic int writes on file

别来无恙 提交于 2019-12-01 01:03:17
I'm writing an application that will have to be able to handle many concurrent accesses to it, either by threads as by processes. So no mutex'es or locks should be applied to this. To make the use of locks go down to a minimum, I'm designing for the file to be "append-only", so all data is first appended to disk, and then the address pointing to the info it has updated, is changed to refer to the new one. So I will need to implement a small lock system only to change this one int so it refers to the new address. How is the best way to do it? I was thinking about maybe putting a flag before the

PostgreSQL and locking

你离开我真会死。 提交于 2019-12-01 01:02:15
Hopefully some smarter DBAs than I can help me find a good solution for what I need to do. For the sake of discussion, lets assume I have a table called 'work' with some number of columns, one of which is a column that represents ownership of that row of work from a given client. The scenario is that I'll have 2 clients connected and polling a table for work to be done, when a row (or some number of rows) shows up, the first client that selects the rows will also update them to imply ownership, that update will remove those rows from being returned to any other client's selects. My question is

SQL Server Lock Timeout Exceeded Deleting Records in a Loop

北城以北 提交于 2019-12-01 00:38:03
问题 I am testing a process that deletes many, many records at once. It cannot TRUNCATE TABLE , because there are records in there that need to stay. Because of the volume, I have broken the delete into a loop similar to this: -- Do not block if records are locked. SET LOCK_TIMEOUT 0 -- This process should be chosen as a deadlock victim in the case of a deadlock. SET DEADLOCK_PRIORITY LOW SET NOCOUNT ON DECLARE @Count SET @Count = 1 WHILE @Count > 0 BEGIN TRY BEGIN TRANSACTION -- added per comment

Update MySQL table in chunks

☆樱花仙子☆ 提交于 2019-12-01 00:02:30
I am trying to update a MySQL InnoDB table with c. 100 million rows. The query takes close to an hour, which is not a problem. However, I'd like to split this update into smaller chunks in order not to block table access. This update does not have to be an isolated transaction. At the same time, the splitting of the update should not be too expensive in terms of additional overhead. I considered looping through the table in a procedure using : UPDATE TABLENAME SET NEWVAR=<expression> LIMIT batchsize, offset, But UPDATE does not have an offset option in MySQL. I understand I could try to UPDATE

Making a password lock for an app?

谁都会走 提交于 2019-11-30 22:13:00
I'm wanting to make a password unlock screen for my app, and I'm not sure how I'd go about it. I'm wanting it to look like the Apple-designed version of it, which is the passcode lock setting screen. How might I go about doing something like this, where as soon as all four digits are entered the code is immediately checked against a pre-set password? Thanks! most likely you create the view and when all the fields are set you check against the known password or you check the hash of the input passkey against the hash you have stored. basically you have a stored password/hash and you check

Locking Linux Serial Port

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 21:54:05
I have an issue that I'm trying to solve regarding the serial port in Linux. I'm able to open, read from, and close the port just fine. However, I want to ensure that I am the only person reading/writing from the port at any given time. I thought that this was already done for me after I make the open() function call. However, I am able to call open() multiple times on the same port in my program. I can also have two threads which are both reading from the same port simultaneously. I tried fixing this issue with flock() and I still had the same problem. Is it because both systems calls are

Python: threading + lock slows my app down considerably

此生再无相见时 提交于 2019-11-30 21:38:45
Say I have a function that writes to a file. I also have a function that loops repeatedly reading from said file. I have both of these functions running in separate threads. (Actually I am reading/writing to registers via MDIO which is why I can't have both threads executing concurrently, only one or the other, but for the sake of simplicity, let's just say it's a file) Now when I run the write function in isolation, it executes fairly quickly. However when I'm running threaded and have it acquire a lock before running, it seems to run extremely slow. Is this because the second thread (read

How to properly avoid Mysql Race Conditions

心已入冬 提交于 2019-11-30 21:32:18
I know this has been asked before, but I'm still confused and would like to avoid any problems before I go into programming if possible. I plan on having an internal website with at least 100 users active at any given time. Users would post an item (inserted into db with a 0 as its value) and that item would be shown via a php site (db query). Users then get the option to press a button and lock that item as theirs (assign the value of that item as their id) How do I ensure that 2 or more users don't retrieve the same item at the same time. I know in programming like c++ I would just use plain